From cppreference.com
typedef/*implementation defined*/fmtflags;staticconstexprfmtflagsdec=/*implementation defined*/staticconstexprfmtflagsoct=/*implementation defined*/staticconstexprfmtflagshex=/*implementation defined*/staticconstexprfmtflagsbasefield=dec|oct|hex;staticconstexprfmtflagsleft=/*implementation defined*/staticconstexprfmtflagsright=/*implementation defined*/staticconstexprfmtflagsinternal=/*implementation defined*/staticconstexprfmtflagsadjustfield=left|right|internal;staticconstexprfmtflagsscientific=/*implementation defined*/staticconstexprfmtflagsfixed=/*implementation defined*/staticconstexprfmtflagsfloatfield=scientific|fixed;staticconstexprfmtflagsboolalpha=/*implementation defined*/staticconstexprfmtflagsshowbase=/*implementation defined*/staticconstexprfmtflagsshowpoint=/*implementation defined*/staticconstexprfmtflagsshowpos=/*implementation defined*/staticconstexprfmtflagsskipws=/*implementation defined*/staticconstexprfmtflagsunitbuf=/*implementation defined*/staticconstexprfmtflagsuppercase=/*implementation defined*/Specifies available formatting flags. It is a
. The following constants are defined:
Constant Explanation
use decimal base for integer I/O: see
use octal base for integer I/O: see
use hexadecimal base for integer I/O: see
dec|oct|hex. Useful for masking operations
left adjustment (adds fill characters to the right): see
right adjustment (adds fill characters to the left): see
internal adjustment (adds fill characters to the internal designated point): see
left|right|internal. Useful for masking operations
generate floating point types using scientific notation, or hex notation if combined with fixed: see
generate floating point types using fixed notation, or hex notation if combined with scientific: see
scientific|fixed. Useful for masking operations
insert and extract bool type in alphanumeric format: see
generate a prefix indicating the numeric base for integer output, require the currency indicator in monetary I/O: see
generate a decimal-point character unconditionally for floating-point number output: see
generate a + character for non-negative numeric output: see
skip leading whitespace before certain input operations: see
flush the output after each output operation: see
replace certain lowercase letters with their uppercase equivalents in certain output operations: see
Example
The following example shows several different ways to print the same result.
Run this code
#include<iostream>intmain(){constintnum=150;// using fmtflags as class member constants:std::cout.setf(std::ios_base::hex,std::ios_base::basefield);std::cout.setf(std::ios_base::showbase);std::cout<<num<<'\n';// using fmtflags as inherited class member constants:std::cout.setf(std::ios::hex,std::ios::basefield);std::cout.setf(std::ios::showbase);std::cout<<num<<'\n';// using fmtflags as object member constants:std::cout.setf(std::cout.hex,std::cout.basefield);std::cout.setf(std::cout.showbase);std::cout<<num<<'\n';// using fmtflags as a type:std::ios_base::fmtflagsff;ff=std::cout.flags();ff&=~std::cout.basefield;// unset basefield bitsff|=std::cout.hex;// set hexff|=std::cout.showbase;// set showbasestd::cout.flags(ff);std::cout<<num<<'\n';// not using fmtflags, but using manipulators:std::cout<<std::hex<<std::showbase<<num<<'\n';}Output:
0x96 0x96 0x96 0x96 0x96 See also
manages format flags
(public member function)
sets specific format flag
(public member function)
clears specific format flag
(public member function)
changes the base used for integer I/O
(function)
changes the fill character
(function template)
fixedscientifichexfloatdefaultfloat
(C++11)(C++11)
changes formatting used for floating-point I/O
(function)
controls whether prefix is used to indicate numeric base
(function)
switches between textual and numeric representation of booleans
(function)
controls whether the + sign used with non-negative numbers
(function)
controls whether decimal point is always included in floating-point representation
(function)
controls whether output is flushed after each operation
(function)
controls whether leading whitespace is skipped on input
(function)
controls whether uppercase characters are used with some output formats
(function)