There are a number of ways of setting the stream manipulations shown below. For simplicity, we will stick with one style for this week.
- Non-paramterized stream manipulators (defined in <ios>)
- endl - add newline and flush buffer
- flush - flush output buffer to destination
- skipws - skip white space in input
- left - left-align values, padding on right with the fill char
- right - right-align values, padding on left with the fill char
- internal - use fill char after leading sign or base indication, but before value
- dec - format numeric values as base 10
- oct - format numeric values as base 8
- hex - format numeric values as base 16
- boolalpha - display bool values as the text "true" or "false"
- noboolalpha - display bool values as the integers 0 or 1
- showbase - display numeric constants with leading base indicator if applicable
- noshowbase - don't display numeric constants with leading base indicator
- showpoint - show decimal point and trailing zeros for floating-point values
- noshowpoint - don't show decimal point and trailing zeros for floating-point values if not needed
- uppercase - display uppercase A through F for hexadecimal values and E for scientific values
- nouppercase - display lowercase a through f for hexadecimal values and e for scientific values
- showpos - show plus signs (+) for positive values
- noshowpos - don't show plus signs (+) for positive values
- Note: ostream starts in a general format, choosing fixed or scientific as the need arises
- scientific - display floating-point numbers in scientific format
- fixed - display floating-point numbers in fixed format
- Note: no easy manipulator for returning ostream to general format
- You can use setiosflags(ios::fixed | ios::scientific) to return to general format
- Parameterized stream manipulators (defined in <iomanip>)
- setw(intVar) - sets the field width; only aplies to next value output
- setprecision(intVar) - sets the digits displayed after the decimal in fixed and scientific formats; the number of significant digits in general format
- setfill(charVar) - set fill character to charVar
- See manips.cpp sample code
- Richard Rasala's handout on C++ IO Manipulators
- A good reference for iostream
- A brief online document regarding IO manipulators