I am trying to find the equivalence of %2d using cout << <<endl
format. how can I do that?
The header <iomanip>
contains the stream manipuator setw
:
cout << setw(2) << myint << endl
You may also be interested in setfill:
cout << setfill('0') << setw(2) << myint << endl
will pad with a 0 instead of a space.
You need setw
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With