Getting hex through Cin
I believe in order to use hex you need to do something like this:
cin >> hex >> x;
cout << hex << x;
you can also replace hex with dec and oct etc.
Actually, You can force >>
operator to get and properly interpret prefixes 0
and 0x
. All you have to do is to remove default settings for std::cin
:
std::cin.unsetf(std::ios::dec);
std::cin.unsetf(std::ios::hex);
std::cin.unsetf(std::ios::oct);
Now, when you input 0x1a you will receive 26.