
Available under Creative Commons-ShareAlike 4.0 International License.
Setting the width for integer family and floating-point family data types must be done for the output of each value. Assume in the following example that age is an integer data type and money is a floating-point data type.
cout « setw(4) « age « endl; cout « setw(8) « money « endl;
Note that each value had to have its own setw(n) where n is an integer number telling it how many positions to use for the output. The iomanip header file (immediately shown) will need to be included in your program.
#include<iomanip> // needed for the setw
- 瀏覽次數:1374