cppreference.com -> C++ I/O Flags

C++ I/O Flags

C++ defines some format flags for standard input and output, which can be manipulated with the flags(), setf(), and unsetf() functions. For example,

    cout.setf(ios::left);

turns on left justification for all output directed to cout.

FlagMeaning
boolalphaBoolean values can be input/output using the words "true" and "false".
decNumeric values are displayed in decimal.
fixedDisplay floating point values using normal notation (as opposed to scientific).
hexNumeric values are displayed in hexidecimal.
internalIf a numeric value is padded to fill a field, spaces are inserted between the sign and base character.
leftOutput is left justified.
octNumeric values are displayed in octal.
rightOutput is right justified.
scientificDisplay floating point values using scientific notation.
showbaseDisplay the base of all numeric values.
showpointDisplay a decimal and extra zeros, even when not needed.
showposDisplay a leading plus sign before positive numeric values.
skipwsDiscard whitespace characters (spaces, tabs, newlines) when reading from a stream.
unitbufFlush the buffer after each insertion.
uppercaseDisplay the "e" of scientific notation and the "x" of hexidecimal notation as capital letters.

You can also manipulate flags indirectly, using the following manipulators. Most programmers are familiar with the endl manipulator, which might give you an idea of how manipulators are used. For example, to set the dec flag, you might use the following command:

  cout << dec;
Manipulators defined in <iostream>
ManipulatorDescriptionInputOutput
boolalphaTurns on the boolalpha flagXX
decTurns on the dec flagXX
endlOutput a newline character, flush the streamX
endsOutput a null characterX
fixedTurns on the fixed flagX
flushFlushes the streamX
hexTurns on the hex flagXX
internalTurns on the internal flagX
leftTurns on the left flagX
noboolalphaTurns off the boolalpha flagXX
noshowbaseTurns off the showbase flagX
noshowpointTurns off the showpoint flagX
noshowposTurns off the showpos flagX
noskipwsTurns off the skipws flagX
nounitbufTurns off the unitbuf flagX
nouppercaseTurns off the uppercase flagX
octTurns on the oct flagXX
rightTurns on the right flagX
scientificTurns on the scientific flagX
showbaseTurns on the showbase flagX
showpointTurns on the showpoint flagX
showposTurns on the showpos flagX
skipwsTurns on the skipws flagX
unitbufTurns on the unitbuf flagX
uppercaseTurns on the uppercase flagX
wsSkip any leading whitespaceX
Manipulators defined in <iomanip>
ManipulatorDescriptionInputOutput
resetiosflags( long f )Turn off the flags specified by fXX
setbase( int base )Sets the number base to baseX
setfill( int ch )Sets the fill character to chX
setiosflags( long f )Turn on the flags specified by fXX
setprecision( int p )Sets the number of digits of precisionX
setw( int w )Sets the field width to wX