我正在尝试在C++中编写一个函数,它将我的字符串“test”拆分成数组中的单独单词。我似乎无法在循环中正确处理这个内容...有没有人有什么思路?它应该输出“this”。
void app::split() {
string test = "this is my testing string.";
char* tempLine = new char[test.size() + 1];
strcpy(tempLine, test.c_str());
char* singleWord;
for (int i = 0; i < sizeof(tempLine); i++) {
if (tempLine[i] == ' ') {
words[wordCount] = singleWord;
delete[]singleWord;
}
else {
singleWord[i] = tempLine[i];
wordCount++;
}
}
cout << words[0];
delete[]tempLine;
}
stringstream
)? - Beta