float input;
cin>>input; // if the user type string in input then throw exception
if(!isdigit(input)){
throw "error";
}
But isdigit also throw exception for a numeric value.
How to solve?
float input;
if (cin>>input) {
//all is good
...
} else {
throw "error";
}
is one way to go. Program will take if
path if the input begins with a number and else
path otherwise.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.