public member function
<ios> <iostream>

std::ios_base::flags

get (1)
fmtflags flags() const;
set (2)
fmtflags flags (fmtflags fmtfl);
Get/set format flags
The first form (1) returns the format flags currently selected in the stream.
The second form (2) sets new format flags for the stream, returning its former value.

The format flags of a stream affect the way data is interpreted in certain input functions and how these are written by certain output functions. See ios_base::fmtflags for the possible values of this function's argument and the interpretation of its return value.

The second form of this function sets the value for all the format flags of the stream, overwriting the existing values and clearing any flag not explicitly set in the argument. To access individual flags, see members setf and unsetf.

Parameters

fmtfl
Format flags to be used by the stream.
ios_base::fmtflags is a bitmask type.

Return Value

The format flags selected in the stream before the call.
ios_base::fmtflags is a bitmask type.

Example

1
2
3
4
5
6
7
8
9
// modify flags
#include <iostream>     // std::cout, std::ios

int main () {
  std::cout.flags ( std::ios::right | std::ios::hex | std::ios::showbase );
  std::cout.width (10);
  std::cout << 100 << '\n';
  return 0;
}

This simple example sets some format flags for cout that affect the insertion operation by printing the value in hexadecimal (0x64) padded right as in a field ten spaces long:
      0x64


Data races

Accesses (1) or modifies (2) 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