Is this possible?

Aug 29, 2010 at 7:50pm
I want to make a sort of tabel.
like:
1
2
Team 1             1 point
Team 23            3 points   


Where all the points are neatly under each other. setw() doesn't work because not all the team names are the same length
Aug 29, 2010 at 8:24pm
Yes, setw is there for that.
eg:
1
2
3
4
    string a="team 1", b="team 1000";
    int sa = 10, sb = 1;
    cout << setw(10) << left << a << setw(2) << right << sa << (sa==1?" point":" points") << endl;
    cout << setw(10) << left << b << setw(2) << right << sb << (sb==1?" point":" points") << endl;
team 1    10 points
team 1000  1 point
Aug 30, 2010 at 8:47am
but I want them both to the right..

EDIT: found how to do it. But why in the beginning setw(10)?
Last edited on Aug 30, 2010 at 8:51am
Aug 30, 2010 at 10:45am
It was a random number, you can make it whatever you want
Aug 30, 2010 at 11:07am
Ok, but how does that make it work?
Aug 30, 2010 at 11:43am
10 is the maximum number of characters that will be filled. It must be larger than the length of the thing you are going to print or you won't notice any change
Topic archived. No new replies allowed.