6.3w+
社区成员
smanip setw ( int n ); <iomanip>
Set field width
Sets the number of characters to be used as the field width for the next insertion operation.
Behaves as if a call to the stream's member ios_base::width with n as its argument was made.
The field width determines the minimum number of characters to be written in some output
representations. If the standard width of the representation is shorter than the field width, the
representation is padded with fill characters (see setfill) at a point determined by the format
flag adjustfield (left, right or internal).
This manipulator is declared in header <iomanip>, along with the other parameterized manipulators:
resetiosflags, setiosflags, setbase, setfill and setprecision. This header file declares the
implementation-specific smanip type, plus any additional operator overload function needed to allow
these manipulators to be inserted and extracted to/from streams with their parameters.
Parameters
n
Number of characters to be used as field width.
Return Value
Unspecified. This function should only be used as a stream manipulator.
Example
// setw example
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
cout << setw (10);
cout << 77 << endl;
return 0;
}
This code uses setw to set the field width to 10 characters.
smanip setw ( int n ); <iomanip>
Set field width
Sets the number of characters to be used as the field width for the next insertion operation.
Behaves as if a call to the stream's member ios_base::width with n as its argument was made.
The field width determines the minimum number of characters to be written in some output
representations. If the standard width of the representation is shorter than the field width, the
representation is padded with fill characters (see setfill) at a point determined by the format
flag adjustfield (left, right or internal).
This manipulator is declared in header <iomanip>, along with the other parameterized manipulators:
resetiosflags, setiosflags, setbase, setfill and setprecision. This header file declares the
implementation-specific smanip type, plus any additional operator overload function needed to allow
these manipulators to be inserted and extracted to/from streams with their parameters.
Parameters
n
Number of characters to be used as field width.
Return Value
Unspecified. This function should only be used as a stream manipulator.
Example
// setw example
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
cout << setw (10);
cout << 77 << endl;
return 0;
}
This code uses setw to set the field width to 10 characters.