+ 1
How to split the strings into arrays in C++?
Assume that a string contains characters or words with whitespaces with between them. Is there any way to split them without using vector?
5 Answers
+ 7
Actually, you need a parser to split the words based on a delimiter and then storing each splitted word (token) into an array or vector .
Take a look at this post at StackOverflow
https://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c
+ 6
You still need a parser dear. But it might become more complex as you expect more from that.
+ 1
edit: my answer here isn't the best solution and it remained after trying to delete it.
you could use another string to work as a buffer. so
string buffer;
int j = 0;
for (int i = 0; i < sentence.length(); i++)
{
if (string[i] == space)
{
//use j and i to add the selected word;
j = i + 1;
}
}
0
Ok another question is that, how do we split the string that the user has enter an input in it?