How do you check that when i use cin to get a number, the user doesn't enter a character? when this happens, the screen goes crazy, and i'd like to protect against this.
thanks,
jmiller
Printable View
How do you check that when i use cin to get a number, the user doesn't enter a character? when this happens, the screen goes crazy, and i'd like to protect against this.
thanks,
jmiller
The screen goes crazy?
If it's not valid you'll have to clear cin's input buffer. I posted a line of code that does this a few days ago.Code:int i;
cin >> i;
if(cin.good())
// i contains a valid value
else
// i doesn't contain a valid value
It gets stuck on the character, and then application goes nuts because it does not like the character.
Whoa never heard of cin.good, well i guss u learn something new every day. jMiller check this page out, u'll find some pretty interesting functions.
http://vbforums.com/showthread.php?s=&threadid=228450
And another thread which is more interesting for your problem.
http://www.vbforums.com/showthread.p...ghlight=ignore