CPPForSchool.com: Variable, Operator & Expression Set 2: Assignment 9

9.
What is the output of following program?
cout << setw(5) << 77 << endl;
cout << setw(5) << 100 << endl;
cout << setw(5) << 12312 << endl;


Based on my research, setw is the function to set the width of spacing, perhaps for indention purposes.  In order to confirm, I will compile the code.





It appears that my assumption for indentation was correct.  However, it was only partially correct.  Upon further testing, I soon came to realize that the setw function not only set the width in regards to indentation, but it also adjusted the text to align towards the right. It is also important to note that I needed to include the "iomanip" library in order to execute the code.

I was able to confirm this by modifying the set value from 5 to 50.  See below for comparison.







Comments

Popular posts from this blog

CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 9

CPPForSchool.com: Array - Single Dimension Set 1 Assignment 6

CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 8