for example i have a string:
string s = "apple | orange | kiwi";
and i searched and there is a way:
stringstream stream(s);
string tok;
getline(stream, tok, '|');
but it only can return the first token “apple”
I wonder that is there any way so it can return an array of string?
Thank you.
Let assume that the string s may be changed. For exammple, string s = “apple | orange | kiwi | berry”;
As Benjamin points out, you answered this question yourself in its title.
Note that your tokens will still have the trailing/leading
<space>characters. You may want to strip them off.