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 !
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 !
One solution is to check for decimal point. Another solution is to check ranges.
Kuphryn
Another solution is to use this
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
*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.Code:if(cin.fail()) { cin.clear(); cin.ignore(100, '\n'); cout << "Doh... data type error. :P" << endl; }
hi Ronin
Yeah i just digged out an old assignment and got it !
thanx anyway, thanx everybody