Formatting output when some names are longer than others
I wrote a program to read names and program scores from a text file and the output has to be formatted into columns evenly like so:
Code:
Snow White 89.50 89.00 B
Sleeping Beauty 89.50 89.00 B
Currently it looks like this:
Code:
Snow White 89.50 89.00 B
Sleeping Beauty 89.50 89.00 B
I can't adjust the lengths to the individuals names because it's read from a file, I've played around with different setw() lengths and left and right alignment and can't get it to format properly. Here's the code:
Code:
cout<<left<<firstName<<" "<<lastName
<<right
<<setw(15)<<average1
<<setw(10)<<average2
<<setw(10)<<average3
<<setw(6)<<grade<<endl;
Any help would be greatly appreciated!