How to cout middle zero with leading zero via one cout statement in C++? -


i need display 3 values parsed packet binary data(0x123400005678).

unsigned int k = 0x1234, l=0x0, m=0x5678; 

i can display four-digit hex value when use cout 3 times.

#include <iostream> #include <iomanip> ... cout << "seperated cout" << endl; cout << hex << setfill ('0') << setw (4) << k; cout << hex << setfill ('0') << setw (4) << l; cout << hex << setfill ('0') << setw (4) << m << endl; ....  seperated cout 123400005678 

but when use 1 cout line, leading 0 of '0x0' omitted...

#include <iostream> #include <iomanip> ... cout << "oneline cout" << endl; cout << hex << setfill ('0') << setw (4) << k << l << m << endl; ...  oneline cout 123405678 

is there anyway display '123400005678' 1 line cout? or using cout 3 times way this?

thank in advance.

field width isn't "sticky", need set again each field print out:

cout << hex << setfill ('0') << setw (4) << k << setw(4) << l << setw(4) << m << endl; 

result:

123400005678 

the fill character is sticky though, want set space character you're done using whatever other value set:

cout << setfill(' '); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -