public member function
<ios>
fmtflags setf ( fmtflags fmtfl );
fmtflags setf ( fmtflags fmtfl, fmtflags mask );
Set specific format flags
The first syntax sets the stream's format flags whose bits are set in
fmtfl leaving unchanged the rest, as if a call to
flags (fmtfl | flags())
The second syntax sets the stream's format flags whose bits are set in both
fmtfl and
mask, and clears the format flags whose bits are set in
mask but not in
fmtfl, as if a call to
flags ( (fmtfl & mask) | (flags() & ~mask) )
Both member functions return the value of the stream's format flags existing before the call.
The format flags of a stream affect the way data is interpreted in certain input functions and how it is written by certain output functions. See
ios_base::fmtflags for the possible values of this function's arguments.
The first syntax of
setf is generally used to set unary format flags:
boolalpha,
showbase,
showpoint,
showpos,
skipws,
unitbuf and
uppercase, which can also be unset directly with
unsetf.
On the other hand, the second syntax is generally used to set a value for one of the selective flags, using one of the field bitmasks as the
mask argument:
fmtfl
format flag value | mask
field bitmask |
| left, right or internal | adjustfield |
| dec, oct or hex | basefield |
| scientific or fixed | floatfield |
The parameterized manipulator
setiosflags behaves in a similar manner as the single-parameter version of this member function.
Parameters
- fmtfl
- Format flags to be set. If the second syntax is used, only the bits set in both fmtfl and mask are set in the stream's format flags; the flags set in mask but not in fmtfl are cleared.
- mask
- Mask containing the flags to be modified.
Return Value
The format flags set in the stream before the call.
Example
1 2 3 4 5 6 7 8 9 10 11 12
|
// modify flags
#include <iostream>
using namespace std;
int main () {
cout.setf ( ios::hex, ios::basefield ); // set hex as the basefield
cout.setf ( ios::showbase ); // activate showbase
cout << 100 << endl;
cout.setf ( 0, ios::showbase ); // deactivate showbase
cout << 100 << endl;
return 0;
}
|
The execution of this example displays something similar to:
See also
- ios_base::flags
- Get/set format flags (public member function)
- ios_base::unsetf
- Clear specific format flags (public member function)
- ios_base::fmtflags
- Type for stream format flags (public member type)
- setiosflags
- Set format flags (function)
- resetiosflags
- Reset format flags (function)