How to break down a sentence of string type into words and store it in a vector of string type in c++? Example
String str="my name";
Into
Vector word={" my","name"}
How to break down a sentence of string type into words and store it in a vector of string type in c++? Example
String str="my name";
Into
Vector word={" my","name"}
You can write a simple loop:
std::vector<std::string> words;
std::istringstream is("my name");
std::string word;
while (is >> word) {
// ...
words.push_back(word);
// ...
}
which in my opinion is good idea because you'll most likely need to do other things with those words apart the simple extraction of them. The body of the loop can be easily extended.