mercredi 5 septembre 2018

using unsetf with hex dec and octal numbers in C++

I have a question about using unsetf. The below is an answer for getting correct input for formatted numbers.

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.

I don't understand the last two unsetf commands for hex and oct. If I use the unsetf command with dec, I get the correct input, which I mean inputting 0x1a and receiving 26.

So what's the point of using unsetf for hex and dec?

Aucun commentaire:

Enregistrer un commentaire