float input; cin>>input; // if the user type string in input then throw exception if(!isdigit(input)){ throw "error"; }
But isdigit also throws an exception for a numeric value.
How to solve?
float input; if (cin>>input) { //all is good ... } else { throw "error"; }
- this is one way. The program will take the if path if input starts with a number and else otherwise.
if
else