I want to get a line of strings and write every word into it's own variable, so that I can use them for example in if clauses.
I tried:
cin >> var1;
cin >> var2;
cin >> var3;
cin >> var4;
But this only works if 4 words are entered. I need a way to count the words because I don't know if it's 1,2,3,4 or more words the user enters.
Maybe there is a way with getting the whole string:
getline(cin, string1);
And cut it into words after that. Sorry, I searched a lot but I can't find a way.
I also tried to write the cinbuffer into a variable, but the only way I can do this is with
cin >> varx;
Which is only usefull if there is something in the cinbuffer. If not, the user gets asked for input again.
EDIT: Just found this, works for me. Thanks Anyway! C++ cin whitespace question