我在我的拆分句子功能有问题。
我的函数的思想分裂的任何一句话,并把它添加到阵列像我的功能错误(拆分句)
例子:
一句话::世界,你好。
我的函数将工作::(阵列[0] =你好,阵列[1] =世界)。
这是我的代码
void splitSentence(char *Sentence, char symb){
const int Size = strlen(Sentence);
string SentenceResult[2];
int count= 0;
stringstream stream;
for(int i=0;i<Size;i++){
stream << Sentence[i];
if((Sentence[i] == symb) || (Sentence[i] == '\0')){
SentenceResult[count] = stream.str();
count++;
stream.str(" ");
}
}
cout << "Stream: " << stream.str() << endl;
cout << "Word [0]: " << SentenceResult[0] << endl;
cout << "Word [1]: " << SentenceResult[1] << endl;
}
结果
流:世界
阵列[0]:你好
阵列[1]://空(必须是“世界”)
我的功能有什么问题。
为什么array [1]是空的。
你怎么叫它? – littleadv 2012-01-05 12:50:14
您是否试过在调试器中逐步完成该功能?那么你会很清楚地看到错误是什么。 – 2012-01-05 12:56:04