-
error trapping ??
What's the quickest way to do error trapping? I remember writing just a few lines of code to trap errors like:
User enter string instead of a float or an int and vice versa
can somebody help coz m getting tired of doing using if and while loops ! :D
-
One solution is to check for decimal point. Another solution is to check ranges.
Kuphryn
-
Another solution is to use this
-
Code:
if(cin.fail())
{
cin.clear();
cin.ignore(100, '\n');
cout << "Doh... data type error. :P" << endl;
}
*should* help for strings or chars into integral types, but its not really a stream error the other way around though it may not be the type your program expected. Just use atoi or whatever to get the integral type.
-
hi Ronin
Yeah i just digged out an old assignment and got it !
thanx anyway, thanx everybody :)