In chapter 11.2.1 of Bjarne Stroustrups principle and practice using C++ he shows the following example:
cin.unsetf(ios::dec); // don’t assume decimal (so that 0x can mean hex)
cin.unsetf(ios::oct); // don’t assume octal (so that 12 can mean twelve)
cin.unsetf(ios::hex); // don’t assume hexadecimal (so that 12 can mean twelve)
So I played around and wrote the following:
int main()
{
std::cin.unsetf(std::ios::dec);
for (int x; std::cin >> x;) std::cout << x << std::endl;
}
Which enables the use of the prefixes 0X
and 0
for hex and octal. But when inputing 12
or any other integer which does not have the prefixes above it is still interpreted as an int. So what does he mean when saying: don’t assume hexadecimal (so that 12 can mean twelve)
?