ios_base::setf
fmtflags setf ( fmtflags fmtfl );
fmtflags setf ( fmtflags fmtfl, fmtflags mask );
ios_base
  cplusplus.com  

Set some format flags.
  The first syntax activates the stream's format flags whose bits are set in mask leaving unchanged the rest, as if a call to flags(mask | flags()).
  The second syntax activates the stream's format flags whose bits are set in both mask and fmtfl and deactivates the format flags whose bits are set in mask but not in fmtfl. As if a call to flags( (fmtfl & mask) | (flags() & ~mask) ).
  Both members returns the previous value of the stream's format flags.

  The stored format flags affects the way data is interpreted in certain input functions and how it is written by certain output functions.
  The values of the different format flags are explained in the fmtflags type reference.

  The first syntax of setf is generally used to activate unary format flags:
    boolalpha, showbase, showpoint, showpos, skipws, unitbuf and uppercase.
  The second syntax of setf can be used to set the selective flags:
    left, right, internal (adjustfield)
    dec,oct,hex (basefield)
    scientific, fixed (floatfield)
  If you want to clear some specific flags you can use unsetf as the opposite of the first syntax of setf.
  If you want to set values for all the format flags or just to retrieve the actual value you can use flags 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 bits set in mask but not in fmtfl are cleared.
mask
Mask containing the bits to be modified.

Return Value.
  The format flags of the stream before the call.

Example.

// modify flags
#include <iostream>
using namespace std;

int main () {
  cout.setf ( ios_base::hex, ios_base::basefield );  // set hex as the basefield
  cout.setf ( ios_base::showbase );                  // activate showbase
  cout << 100 << endl;
  cout.setf ( 0, ios_base::showbase );               // deactivate showbase
  cout << 100 << endl;
  return 0;
}
The execution of this example shall display:
  0x64
  64

See also.
  flags, unsetf
  fmtflags type, ios_base class


© The C++ Resources Network, 2001