Link to home
Start Free TrialLog in
Avatar of lcoolsingh
lcoolsingh

asked on

Formatting I/O

Hello all,

I have a simple question regarding how to perform some formatting in c++. I know you can use setw(xx) or width(), but when i have the following case below, things get out of hand:

Example:

Text              10
MoreText               10.

Basically i want to able to line things up, so in the above example i would like the number 10 to be lined in the same column as the one before, but this does not seem to be happening. I've currently got code like this:

cout << "Text" << setw(10) << 10<< endl;
cout << "MoreText" << setw(10) << 10<< endl;

Is their a way round this? I know the reason why this is happending, but dont know of a way to control formatting of this nature.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lcoolsingh
lcoolsingh

ASKER

But that means that the first ends up like this:

         Text            10
  MoreText            10

I think what needs to be done is to use setiosflags(ios::left).

thanks