1 2
|
//this stops characters such as newline if the end-of-file is reached. sets the eofbit flag
cin.ignore(1000, '\n');
|
What you're doing with this ignore function as written, is throwing away characters from the input stream until either 1000 characters have been thrown out or the newline character '\n' has been found, or if there are less than 1000 characters in the stream and no '\n', then it will set the end of bit flag.
cin leaves a '\n' in the stream and if not cleared, getline will read the '\n' and not grab your string. So AFTER your cin, or before the getline, you need to use an ignore to clear out that '\n'. Otherwise your getline call will not grab your string from the stream.
Here's what your stream looks like.
you enter 3 and hit enter.
cin grabs the 3 and leaves '\n'.
Then you enter the player name.
getline grabs the '\n' left from the cin and leaves bob baker in the stream.
Then another cin asks for an int and you enter 88\n.
Now your stream looks like -bob baker88\n.
The cin looks for an int so it throws everything out until it finds and int, so it throws away bob baker and reads 88 and then leaves the '\n'.
So, all the input through the first players score would look like this in the buffer.
3\nbob baker88\n
You want to read the 3 with cin, ignore the newline, read bob baker with getline, read 88 with cin and then ignore the newline.
Get it?