To my knowledge there isn't a way to restrict the input, but you can certainly filter input and handle exception cases on your own! An easy way to fix your incoming input is to put it into a string first and then use formulas to determine if it fits your required model.
For instance, if I needed to verify that the incoming text was simply numerical:
1 2 3 4 5 6 7
bool isNumeric(const string& str){
for(int a = 0; a < str.size(); a++){
if (!isdigit(str[a]))
returnfalse;
}
returntrue;
}
Have a look at the examples. You can use the good function to see if the last stream operation worked: if the input is bad this function returns false
The method of using isdigit isn't very good for floating point numbers like double, one has to account for +, -, e, E in the scientific format (+1.2e+3), as well as a host of error states like overflow, underflow etc.