tags:

views:

47

answers:

2

I am trying to find the equivalence of %2d using cout << <<endl format. how can I do that?

+4  A: 

You need setw

codaddict
so I would do:setw (2) fo %2d?
EquinoX
Yes. cout<<setw(2)<<value<<endl;
codaddict
+7  A: 

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.

John Ledbetter