I\'m writing a program which needs to read a text file and check first line of the text file for a number between 0 to 10. I have come up with a couple of solutions but ther
I would probably read the line with std::getline, then use a Boost lexical_cast to convert to int. It will throw an exception unless the entirety of the input string can be converted to the target type -- exactly what you want.
Of course, you'll also need to check that the converted result is in the correct range, and also throw the exception if it's out of range.