When using setw with cout, how do i center align the text/numbers within the specified width?
Thanks
When using setw with cout, how do i center align the text/numbers within the specified width?
Thanks
There’s no specified stream manipulator that does that, you need to calculate the centre column coordinate yourself, then call gotoxy().
Be a leader and not a follower.
subdene's suggestion is good, but remember that gotoxy() is non-standard and non-portable.
If that isn't an issue - should always be, but let's deal with that one later - use subdene's idea.
(Off-hand, I don't know of a better way. )
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow
It would be something like so...When using setw with cout, how do i center align the text/numbers within the specified width?
cout << setfill('*') << left //left justifies
<< setfill('$') <<right //right justifies
<< setw(6) << endl; // set width to 6 places
I hope this was want your looking for.
Later
cj
"Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
-Bruce Lee