setf [C++ Reference]
Keywords: io,setf
Date: 2009-03-09T12:23:05-0700

[[setf]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## 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

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •