Example 2 – cont’d
n
#include <iostream.h>
n
#include <iomanip.h>
n
int main() {
n
cout << setw(3) << 6
<< endl
n
<< setw(3) << 18
<< endl
n
<< setw(3) << 124
<< endl
n
<<"---" << endl << (6 + 18 + 124) << endl;
n
return 0;
n
}
n
6
n
18
n
124
n
---
n
148
n
Since setw(3) field width manipulators are
given, cout allocates 3 spaces for each
number as it is received