guys, let's say I a sentence
string sentence 开发者_运维问答= "Hello, I like C++ programming language!";
and I want to put each word into an array of strings... I think I could use a delimiter
size_t space = sentence.find(" ");
string words[]; //putting individual words here
for(int i=0; i < sentence.length(); i++)
{
words[i] =
//incrementing delimiter to next space here
}
any help appreciated. Thanks
you can use copy() in algorithm library
string s("Your String");
istringstream iss(s);
vector<string> words;
copy (istream_iterator(iss),istream_iterator(),back_inserter(words));
The code should be like that, and i think using Vector is better than an array of strings
精彩评论