The if statement is completely ignored in this program

Oct 30, 2014 at 5:02am
.....
Last edited on Nov 2, 2014 at 7:11am
Oct 30, 2014 at 5:24am
Before line 66, add:

std::cin.ignore(10000,'\n');

There's a funny thing when you use cin to input into a character- it only inputs one character. That means that the newline character that you put in when you hit enter to insert the character is still floating in the input stream. Once the code asks for a new string, it reads the newline and terminates the input. What the code I just showed does is ignores everything in the buffer up until and including the newline, or 10000 characters. That way, it rids of that pesky newline causing your problems.
Oct 30, 2014 at 5:43am
Ah thank you! I will be sure to remember that cin.ignore function. Should be extremely useful.
Topic archived. No new replies allowed.