ios_base::setf

Sets the specified flags.

fmtflags setf(
    fmtflags _Mask
);
fmtflags setf(
    fmtflags _Mask,
    fmtflags _Unset
);

_Mask

The flags to turn on.

_Unset

The flags to turn off.

The previous format flags

The first member function effectively calls flags(_Mask | _Flags) (set selected bits) and then returns the previous format flags. The second member function effectively calls flags(_Mask & fmtfl, flags & ~_Mask) (replace selected bits under a mask) and then returns the previous format flags.

// ios_base_setf.cpp
// compile with: /EHsc
#include <iostream>

int main( ) 
{
   using namespace std;
   int i = 10;
   cout << i << endl;

   cout.unsetf( ios_base::dec );
   cout.setf( ios_base::hex );
   cout << i << endl;

   cout.setf( ios_base::dec );
   cout << i << endl;
   cout.setf( ios_base::hex, ios_base::dec );
   cout << i << endl;
}

10
a
10
a

Header: <ios>

Namespace: std

Show: