You need to use either cout or printf, not both.
printf("%06X ", 0xABCDEF);
or
cout << hex << 0xABCDEF;
When you do both, cout prints the result of the printf function, which is the number of characters printed (six characters and a space).
source
share