如何使用getline(cin, input);
分割輸入字符串以輸入變量?我想分裂成這樣的字符數組:將字符串拆分爲數組C++
char[] = { // What goes here to make it read the input variable and split it into chars }
有沒有辦法做到這一點?
那你們都是新帖嗎?哪一個最好?這裏是凱撒密碼代碼我需要修改在字符數組來讀取輸入變量和存儲它的字符:
// Test Code ONLY
// Not A Commercial Program OR A Crypter
// THIS IS A TEXT CIPHERER
#include <windows.h>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
int main()
{
string in;
string out;
char lower[25] = {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z};
char upper[25] = {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z};
char upcip[25] = {Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A};
char locip[25] = {z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i,h,g,f,e,d,c,b,a};
cout << "Enter PlainText: ";
getline(cin, in);
// which sample goes here to read the input var char by char, then store the chars in order in a char array in your opinion?
return 0;
}
你爲什麼需要這個? 'std :: string :: c_str()'將返回一個指向空終止字符數組的指針。 – jrok
可能的重複[如何在C++中標記字符串?](http://stackoverflow.com/questions/53849/how-do-i-tokenize-a-string-in-c) –
用代碼I更新的OP試圖編輯。 – hCon