int intThis;
cin >> intThis;
__end__
--------------------
This reads a decimal number in no matter what.
--------------------
cin >> /* oct | dec | hex */ >> intThis;
10 is output as 10, 012, 0xA
010 is output as 8, 010, 0x8
0x10 is output as 0, 00, 0x0
--------------------------
If I play with the base manipulator and just enter 10
.. oct ..
Outputs 8 010 0x8
In short, a g++ compiled program is perfectly happy to cin numerals and
treat them as a string of any base. However, it seems to be completely
oblivious to the 0.. and 0x prefixes. I haven't tried the [A-Fa-f] hex
numbers, but I bet it cant treat them as parts of a number either.
------------------------------
Is there a flag or parameter that I need to set to get C++ to automatically
read in octal and hex integers?
I can always write code to scan and manipulate the input appropriately.
However, there are two reasons to avoid this:
A) It is for a class, so if the behavior is a C++ built in, I need to get
it to work.
B) As an aspiring programmer I embrace laziness as a virtue.
--------------------------
Trent Shipley
Work:
(602) 522-7502
mailto:tshipley@symbio-tech.com
http://www.symbio-tech.com