Extra digits with printf Hex

Why am I getting extra digits after a string of hex digits when using printf?

cout << printf("%06X ", 0xABCDEF);

manufactures: ABCDEF 7

So where does 7 go from and how can I get rid of it?

+3
source share
4 answers

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).

+11
source

You pass the result of the printf operation to cout.

Generally speaking, you are using either printf or cout.

printf("%06X",0xABCDEF); //will do what you want in a C-like way

and

std::cout << std::hex << 0xABCDEF; //is the C++ iostream way
+7
source

Try

cout << hex << 0xABCDEF;

"7" - printf(). cout, printf().

+4

printf cout. printf , .

The 7 , printf , . 7 cout, .

cout, - Boost.Format, iostreams .

+3

Source: https://habr.com/ru/post/1764596/


All Articles