Basically I want to take an input line with multiple words (length not specified), word by word and add each word to a vector. I can use getline and write a function to split it but wanted a more concise way to read each word and keep on adding it to a vector till Enter key is pressed. Something like this till enter key is pressed. Thanks!
vector<string> inp;
while(????)
{
string str;
cin>>str;
inp.push_back(str);
}
I am looking for something without using libraries, just some way of stop taking input when enter key is pressed, some condition in the while loop in the above code such that when enter key is encountered, it breaks out and stops taking input. Something like:
while(1)
{
string str;
cin>>str;
// if( character entered =='\0')
//break;
inp.push_back(str);
}
Any help would be appreciated.