public member type
<ios> <iostream>

std::ios_base::fmtflags

Type for stream format flags
Bitmask type to represent stream format flags.
This type is used as its parameter and/or return value by the member functions flags, setf and unsetf.

The values passed and retrieved by these functions can be any valid combination of the following member constants:


fieldmember constanteffect when set
independent flagsboolalpharead/write bool elements as alphabetic strings (true and false).
showbasewrite integral values preceded by their corresponding numeric base prefix.
showpointwrite floating-point values including always the decimal point.
showposwrite non-negative numerical values preceded by a plus sign (+).
skipwsskip leading whitespaces on certain input operations.
unitbufflush output after each inserting operation.
uppercasewrite uppercase letters replacing lowercase letters in certain insertion operations.
numerical base
(basefield)
decread/write integral values using decimal base format.
hexread/write integral values using hexadecimal base format.
octread/write integral values using octal base format.
float format
(floatfield)
fixedwrite floating point values in fixed-point notation.
scientificwrite floating-point values in scientific notation.
adjustment
(adjustfield)
internalthe output is padded to the field width by inserting fill characters at a specified internal point.
leftthe output is padded to the field width appending fill characters at the end.
rightthe output is padded to the field width by inserting fill characters at the beginning.

Three additional bitmask constants made of the combination of the values of each of the three groups of selective flags can also be used:

flag valueequivalent to
adjustfieldleft | right | internal
basefielddec | oct | hex
floatfieldscientific | fixed

The values of these constants can be combined into a single fmtflags value using the OR bitwise operator (|).

These constants are defined as public members in the ios_base class. Therefore, they can be refered to either directly by their name as ios_base members (like ios_base::hex) or by using any of their inherited classes or instantiated objects, like for example ios::left or cout.oct.

These values of type ios_base::fmtflags should not be confused with the manipulators that have the same name but in the global scope, because they are used in different circumstances. The manipulators cannot be used as values for ios_base::fmtflags, as well as these constants shouldn't be used instead of the manipulators. Notice the difference:
1
2
ios_base::skipws     // constant value of type ios_base::fmtflags
skipws               // manipulator (global function) 


Notice that several manipulators have the same name as these member constants (but as global functions instead) - see manipulators. The behavior of these manipulators generally corresponds to the same as setting or unsetting them with ios_base::setf or ios_base::unsetf, but they should not be confused! Manipulators are global functions and these constants are member constants. For example, showbase is a manipulator, while ios_base::showbase is a constant value that can be used as parameter with ios_base::setf.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// using ios_base::fmtflags
#include <iostream>     // std::cout, std::ios_base, std::ios,
                        // std::hex, std::showbase
int main () {

  // using fmtflags as class member constants:
  std::cout.setf (std::ios_base::hex , std::ios_base::basefield);
  std::cout.setf (std::ios_base::showbase);
  std::cout << 100 << '\n';

  // using fmtflags as inherited class member constants:
  std::cout.setf (std::ios::hex , std::ios::basefield);
  std::cout.setf (std::ios::showbase);
  std::cout << 100 << '\n';

  // using fmtflags as object member constants:
  std::cout.setf (std::cout.hex , std::cout.basefield);
  std::cout.setf (std::cout.showbase);
  std::cout << 100 << '\n';

  // using fmtflags as a type:
  std::ios_base::fmtflags ff;
  ff = std::cout.flags();
  ff &= ~std::cout.basefield;   // unset basefield bits
  ff |= std::cout.hex;          // set hex
  ff |= std::cout.showbase;     // set showbase
  std::cout.flags(ff);
  std::cout << 100 << '\n';

  // not using fmtflags, but using manipulators:
  std::cout << std::hex << std::showbase << 100 << '\n';

  return 0;
}


The code shows some different ways of printing the same result, using both the fmtflags member constants and their homonymous manipulators.

Output:
0x64
0x64
0x64
0x64
0x64

See also