我试图插入下,使用矢量++由空格分隔成字符串的阵列而不的字符串。例如:C++:将字符串分割为一个数组
using namespace std;
int main() {
string line = "test one two three.";
string arr[4];
//codes here to put each word in string line into string array arr
for(int i = 0; i < 4; i++) {
cout << arr[i] << endl;
}
}
我所要的输出是:
test
one
two
three.
我知道已经有很多要求的字符串>数组用C++的问题。我意识到这可能是一个重复的问题,但我找不到满足我的条件的任何答案(将字符串拆分为数组而不使用向量)。如果这是一个重复的问题,我很抱歉。
你会如何开始在单独的行上打印每个单词? –
使用substr并找到 – 999k
或'strtok'。 。 –