In order to learn C++, I\'m translating a program I wrote in Python.
I wrote this
n = 0
while n < 2:
try:
n = int(raw_input(\'Please inser
For a situation like this, you'd probably want to read the input as a string, then inspect the string (e.g., "contains only digits, up to a maximum of N digits"). If and only if it passes inspection, parse an int
out of it.
It's also possible to combine the inspection and conversion--for example, Boost lexical_cast
will attempt to parse an int out of the string, and throw an exception if it can't convert the whole thing to an int.