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
Printable View
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
I guess you use scanf().
Use one or several fgetc() instead.
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).
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.