|
-
September 22nd, 2010, 11:08 AM
#1
Exception - inputted a character for an integer
Hi,
i accidentally given input as character for a integer variable in the console.....the program went crazy and just flooded the console.....
so, is there any way to handle this exception......
how to achieve that
thank you
-
September 22nd, 2010, 11:12 AM
#2
Re: Exception - inputted a character for an integer
I guess you use scanf().
Use one or several fgetc() instead.
-
September 22nd, 2010, 11:27 AM
#3
Re: Exception - inputted a character for an integer
You simply have to test whether the input was successful. If not, you'll need to clear the error flags on the stream before trying again.
It would help to know if you're using <cstdio> IO (scanf, etc) or <iostream> IO (ifstream, cin, etc).
-
September 22nd, 2010, 11:34 AM
#4
Re: Exception - inputted a character for an integer
 Originally Posted by Lindley
You simply have to test whether the input was successful. If not, you'll need to clear the error flags on the stream before trying again.
It would help to know if you're using <cstdio> IO (scanf, etc) or <iostream> IO (ifstream, cin, etc).
okay....thank you...
i used cin.ignore,
cin.clear, cin.fail
-
September 22nd, 2010, 12:50 PM
#5
Re: Exception - inputted a character for an integer
Read this one.
http://www.parashift.com/c++-faq-lit....html#faq-15.3
In fact just for fun read the entire section 15. This is critical information for all beginners who are writing console applications.
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
|