#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
usingnamespace std;
int main()
{
string line;
getline(cin,line); // grabs entire line after user presses enter;
istringstream iss(line); // put input string in stream
vector<string> words(istream_iterator<string>(iss),istream_iterator<string>{}); // populate vector with "words"
for(vector<string>::iterator i = words.begin(); i != words.end(); ++i)
{
cout << *i << endl; // display each word on its own line
}
return 0;
}
jlb,
If it was friendly enough I wouldn't ask here.
patriic48,
Why are you explaining me my own code? I know what I have done. But it still won't work the way I want to.
As long as those people realize the code doesn't actually do the same thing as the OP then that would be fine. Look at the differing placement of the break statement.
Now back to topic:
If you really must have the data entry stop when the user just types the enter key you could try something like:
I guess this is the right moment to ask - what exactly cin.ignore does (with these arguments)? I'm aware it is needed when using getline right after cin.
This would keep extracting characters from cin until it reaches 100 characters or encounters an endline character. This helps ensure that subsequent calls to cin aren't getting any leftover buffer contents.