How to throw exception when user stores string in float variable?

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?

+5
source share
1 answer
 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.

+5
source

All Articles