Click here to Skip to main content
15,903,523 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have problem aligning text:

Student Name           Test Score  Grade
Donald, Duckey               85      B
Goofy, Goof                  89      B
Balto, Brave                 93      A
Smitn, Snow                  93      A
Wonderful, Alice             89      B

I am using the <iomanip> header for the "setw" and align "left" functions but I only manged to achieve something like this:
Student Name           Test Score  Grade
Donald   ,Duckey            85        B
Goofy    ,Goof              89        B
Balto    ,Brave             93        A
Smitn    ,Snow              93        A
Wonderful,Alice             89        B

Here is my code:
C++
outFile << left << setw(9)
<< student[i].studentLName << ","
<< left << setw(10) << student[i].studentFName
<< right << setw(10) << student[i].testScore << setw(9)
<< student[i].grade << endl;


Does anyone have an idea on how to fix it? Or maybe different approach?
Posted

1 solution

I would build the complete name by concattenating first-name, comma, last-name. Then you can write this to the text file as one item with predetermined width and the comma will appear at the correct place.
 
Share this answer
 
Comments
CPallini 6-Dec-13 2:38am    
5.For sure better than my own solution.
ProDavy 6-Dec-13 3:30am    
Thank you for your help!
nv3 6-Dec-13 3:49am    
My pleasure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900