I just started learning C++. I was just playing around with it and came across a problem which involved taking input of a string word by word, each word separated by a white
Put the line in a stringstream and extract word by word back:
#include
#include
using namespace std;
int main()
{
string t;
getline(cin,t);
istringstream iss(t);
string word;
while(iss >> word) {
/* do stuff with word */
}
}
Of course, you can just skip the getline part and read word by word from cin directly.
And here you can read why is using namespace std considered bad practice.