To summarize briefly the link that
Handy Andy posted, a cin >> operation reads up until white space, so if the user enters "John Wood", a single cin operation retrieves only "John" from the input buffer, leaving "Wood" in the input buffer.
As
Handy Andy said you should use std::getline(). getline() reads until a specified delimiter, by default \n, thereby returning all of "John Wood". You indicate that you tried getline(), but don't really indicate why you think that didn't work.
BTW, in the code snippet you posted, player1 and player2 are not defined. It's not clear if you have declared player1 and player2 as std::string.
I have pretty much the same issue a bit later when I'm asking for input for the game itself |
When switching between cin >> and getline(), it's a good idea to do:
1 2
|
cin.clear(); // reset any error flags on the stream
cin.ignore (1000); // eat any extraneous characters in the input buffer
|