0

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

ardiyu07
  • 1,790
  • 2
  • 17
  • 29
miatech
  • 2,150
  • 8
  • 41
  • 78

1 Answers1

0

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

ardiyu07
  • 1,790
  • 2
  • 17
  • 29