loop through words in string c++
// C++ program to Iterate through
// a String word by word
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
// Driver code
int main()
{
// Get the String
string str = "GeeksforGeeks is a computer "
"science portal for Geeks";
// Initialise the istringstream
// with the given string
istringstream iss(str);
// Iterate the istringstream
// using do-while loop
do {
string subs;
// Get the word from the istringstream
iss >> subs;
// Print the word fetched
// from the istringstream
cout << subs << endl;
} while (iss);
return 0;
}