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::setf

public member function
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 internaladjustfield
dec, oct or hexbasefield
scientific or fixedfloatfield

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:

0x64
64

See also