public member function
<ios> <iostream>

std::ios_base::setf

set (1)
fmtflags setf (fmtflags fmtfl);
mask (2)
fmtflags setf (fmtflags fmtfl, fmtflags mask);
Set specific format flags
The first form (1) 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 form (2) 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 return the value of the stream's format flags 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 form of setf (1) is generally used to set independent format flags: boolalpha, showbase, showpoint, showpos, skipws, unitbuf and uppercase, which can also be unset directly with member unsetf.

The second form (2) 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 internaladjustfield
dec, oct or hexbasefield
scientific or fixedfloatfield

The parameterized manipulator setiosflags behaves in a similar way as the first form of this member function (1).

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.

Member type fmtflags is a bitmask type (see ios_base::fmtflags).

Return Value

The format flags selected in the stream before the call.

Example

1
2
3
4
5
6
7
8
9
10
11
// modifying flags with setf/unsetf
#include <iostream>     // std::cout, std::ios

int main () {
  std::cout.setf ( std::ios::hex, std::ios::basefield );  // set hex as the basefield
  std::cout.setf ( std::ios::showbase );                  // activate showbase
  std::cout << 100 << '\n';
  std::cout.unsetf ( std::ios::showbase );                // deactivate showbase
  std::cout << 100 << '\n';
  return 0;
}

Output:
0x64
64


Data races

Modifies the stream object.
Concurrent access to the same stream object may cause data races.

Exception safety

Basic guarantee: if an exception is thrown, the stream is in a valid state.

See also