开发者

how can I split a sentence into words using Visual C++

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜