Use of setw() manipulator
Demonstration of setw manipulation for setting display width
- Learning to use setw io manipulator to set field width for text as well as numbers.
This include file is required for all IO manipulation for display purposes.
This string will be used for display
Since the string is of 5 characters setting display width to 5 will not have any effect.
Now the width is set to 1 more than given string width so the string will be printed after leaving 1 space.
Here the string hello will be printed after leaving 2 spaces.
Here the string will again be printed from start of the line. This also demonstrates that previous effect of setw will not be there.
This decimal number will be used to test the affect of setw on numbers.
This is number printing from the left most column.
Since the number is of 6 digits including the decimal so it will start printing after leaving first 4 columns as the width has been set to 10 columns.
- setw reference can be seen at
Suggested Filename(s): setw.cpp
sunmitra| Created: 15-May-2018 | Updated: 15-Sep-2018|