开发者

formatting an integer output using ostream

开发者 https://www.devze.com 2022-12-26 20:31 出处:网络
I am trying to find the equivalence of %2d using cout << <&l开发者_运维百科t;endl format.how can I do that?The header <iomanip> contains the stream manipuator setw:

I am trying to find the equivalence of %2d using cout << <&l开发者_运维百科t;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

0

精彩评论

暂无评论...
验证码 换一张
取 消