mercredi 25 février 2015

Printed unsigned chars as hex are too long

Lets assume I have this very simple example:



vector<unsigned char> bytes {0xFF, 0xFF, 0xFD};

for (const char & v: bytes) {
cout << hex << setfill('0') << setw(2) << uppercase << static_cast<unsigned>(v) <<" ";
}

cout << endl;


This gives:



FFFFFFFF FFFFFFFF FFFFFFFD


However, I would like to have it short, like:



FF FF FD


So why do I get some many extra "FFFFF"?


Aucun commentaire:

Enregistrer un commentaire