Hy,
I want to read a number in c++ with the cin function. I know there are a lot of threads but I didn't found a perfekt solution.
First I tried it with cin.fail() function. But if I input a number like this 12asdf it reads the 12 correct and didn't throw an error.
Then I tried to read a string and convert it with the atoi() function but if I read a string like this 12asdf I have the same problem. It reads the 12 correct and throws no error.
The I tried it with the function but the all_of function isn't available in visual 2013.
if ( std::all_of(input.begin(), input.end(), std::isdigit) )
{
//input is integer
}
How can I check an input like this 12asdf and throw an error?
Best regards