Text Output Alignment

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; 
You probably want to use setw before outputting the name and id_number.
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
Topic archived. No new replies allowed.