I am trying to read a line of input into a vector. I want to stop adding to the vector when the end of the line is reached. I have tried this:
string word;
vector<string> sv;
cout << "Type a sentence containing 6 words:";
cin >> word;
while (word != "\n"
{
sv.push_back(word);
cin >> word;
}
This doesn't seem to work. None of the lines below this code get executed for some reason. I changed the "\n" to "." and put in the . at the end of the line of input and that wroked just fine. I guess I can't figure out how to recognize the ond of line for the while loop. Thanks
string word;
vector<string> sv;
cout << "Type a sentence containing 6 words:";
cin >> word;
while (word != "\n"
{
sv.push_back(word);
cin >> word;
}
This doesn't seem to work. None of the lines below this code get executed for some reason. I changed the "\n" to "." and put in the . at the end of the line of input and that wroked just fine. I guess I can't figure out how to recognize the ond of line for the while loop. Thanks