Text Output Alignment

Nov 1, 2016 at 5:18pm
How can the output of a string be fixed to a position to where regardless of the amount of characters in the input, the alignment won't be thrown off?

I'm working on a Payroll project for my Computer Science course.
Here's the entire code I have.

here's the output for the strings name and id_number.
My issue is, if I make the name longer or shorter, the position of "I.D. Number" changes in correlation to that.

1
2
3
4
outfile << setw (30) << "" << "Employee Name: " << left << name << setw (7) << "" << right << "I.D. Number: " << id_number << endl; 
		
outfile << endl << endl; 
Nov 1, 2016 at 6:26pm
You probably want to use setw before outputting the name and id_number.
Nov 8, 2016 at 3:08pm
Bro setw() is the manipulator which allows you to specify a column for an expression. Basically it sets the width of your expression as its name stands for "set width". You can use keyword "left" or "right" in your output stream to specify whether value expression should start from left side or right side. For further explanation, I would like you to read http://www.allaboutcomputing.net/2016/11/top-5-c-manipulators-every-programmer.html?m=1
Last edited on Nov 8, 2016 at 3:16pm
Topic archived. No new replies allowed.