Hey, I'm trying to take in strings as an input and place them in a vector, stopping when the user presses the return key.
The relevant part of the code looks like this at the moment:
1 2 3 4 5
while (...)
{
cin >> StringPasser;
Vector.push_back(StringPasser);
}
I need something that recognises the end condition (ie. \n input) and breaks. I tried making the while loop finish when StringPasser = the return character, but that didn't work.
But it works only when the last string is followed with the new-line symbol without any spaces. If you want the last, you should do it "with your arms" by for cycle.
Could you be more specific about the problem?
Is StringPasser a char or a string?
Vector is of type char or string?
Sorry, should have specified.
Both are of type string, ie. initialised as:
1 2
string StringPasser
vector<string> Vector
Are you trying to take input in the form of per character?
But it works only when the last string is followed with the new-line symbol without any spaces.
I want it to take the input as whole words, or sentences (which it will currently do), but to end when the return key is pressed, irrespective of what precedes it.