Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
filebuf
fstream
ifstream
ios
iostream
ios_base
istream
istringstream
ofstream
ostream
ostringstream
streambuf
stringbuf
stringstream
objects:
cerr
cin
clog
cout
types:
fpos
streamoff
streampos
streamsize
ios_base
ios_base::ios_base
ios_base::~ios_base
member classes:
ios_base::failure
ios_base::Init
member functions:
ios_base::flags
ios_base::getloc
ios_base::imbue
ios_base::iword
ios_base::precision
ios_base::pword
ios_base::register_callback
ios_base::setf
ios_base::sync_with_stdio
ios_base::unsetf
ios_base::width
ios_base::xalloc
member types:
ios_base::event
ios_base::event_callback
ios_base::fmtflags
ios_base::iostate
ios_base::openmode
ios_base::seekdir


ios_base::fmtflags

public member type

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
35
// using ios_base::fmtflags
#include <iostream>
using namespace std;
int main () {
  // using fmtflags as class member constants:
  cout.setf (ios_base::hex , ios_base::basefield);
  cout.setf (ios_base::showbase);
  cout << 100 << endl;
  // using fmtflags as inherited class member constants:
  cout.setf (ios::hex , ios::basefield);
  cout.setf (ios::showbase);
  cout << 100 << endl;
  // using fmtflags as object member constants:
  cout.setf (cout.hex , cout.basefield);
  cout.setf (cout.showbase);
  cout << 100 << endl;
  // using fmtflags as a type:
  ios_base::fmtflags ff;
  ff = cout.flags();
  ff &= ~cout.basefield;   // unset basefield bits
  ff |= cout.hex;          // set hex
  ff |= cout.showbase;     // set showbase
  cout.flags(ff);
  cout << 100 << endl;
  // not using fmtflags, but using manipulators:
  cout << hex << showbase << 100 << endl;
  return 0;
}


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

See also