When using setw with cout, how do i center align the text/numbers within the specified width?
Thanks
Printable View
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().
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
It would be something like so...Quote:
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