d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Quick C++ Question About Cin.get And Cin.ignore
Add Reply New Topic New Poll
Member
Posts: 36,389
Joined: Jul 18 2008
Gold: 3,192.00
Oct 22 2012 05:01pm
So I'm reviewing these, and my book is talking about how using cin.ignore helps problems with cin.get reading the null terminator from a previous cin statement.

Here is the example in the book:

Code

char ch;
int number;

cout << "Enter a number: ";
cin >> number;
cin.ignore( );
cout << "Enter a character: ";
ch = cin.get( );
cout << "Thank you.\n"

return 0;


The regular font represents what is output to the screen, the bold represents the user input:

Quote
Enter a number: 100 [Enter]
Enter a character: Z [Enter]
Thank you.


But because cin.get reads the next character, wouldn't it skip to outputting "Thank you." even before the user pressed Enter?
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll