Originally Posted by
laserlight
Well, if you are only allowed to read in using formatted operator>> to an int, then I suspect that the problem either cannot be solved, or requires some cunning yet pointless hack. The problem is that you have no way to determine if the input should be read in decimal or hexadecimal representation. This is easy to decide if you could read in the first two characters separately: if you detect the "0x" prefix, you just set the hex flag and read.
EDIT:
Okay, an idea for a cunning yet pointless hack has just crossed my mind: read to the int variable in decimal. If the read fails, clear the error flags, then set the hex flag and read in as hex. If that fails, zap the user for entering invalid input.