setf

Syntax:

    fmtflags stream::setf( fmtflags flags );
    fmtflags stream::setf( fmtflags flags, fmtflags needed );

The function setf() sets the io_stream_format_flags of the current stream to flags. The optional needed argument specifies that only the flags that are in both flags and needed should be set. The return value is the previous configuration of io_stream_format_flags. For example:

     int number = 0x3FF;
     cout.setf( ios::dec );
     cout << "Decimal: " << number << endl;
     cout.unsetf( ios::dec );
     cout.setf( ios::hex );
     cout << "Hexadecimal: " << number << endl;

Note that the preceding code is functionally identical to:

     int number = 0x3FF;
     cout << "Decimal: " << number << endl << hex << "Hexadecimal: " << number
  << dec << endl;

thanks to io_stream_manipulators.

Related Topics: flags, unsetf