|
-
Feb 26th, 2003, 08:17 PM
#1
Thread Starter
Addicted Member
characters entered when numbers wanted
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
-
Feb 27th, 2003, 07:04 AM
#2
The screen goes crazy?
Code:
int i;
cin >> i;
if(cin.good())
// i contains a valid value
else
// i doesn't contain a valid value
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 28th, 2003, 11:44 PM
#3
Fanatic Member
It gets stuck on the character, and then application goes nuts because it does not like the character.
-
Feb 28th, 2003, 11:52 PM
#4
Member
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
Death is always smiling down on us, the only thing we can do is smile back
-
Mar 1st, 2003, 07:17 AM
#5
And another thread which is more interesting for your problem.
http://www.vbforums.com/showthread.p...ghlight=ignore
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|