Contents|Index|Previous|Next

Choices in formatting

The following methods control (or report on) settings for some details of controlling streams, primarily to do with formatting output.

    char ios::fill ()const
    Method

Returns the current padding character.

    char ios::fill (char padding)
    Method

Set the padding character. You can also use the manipulator, setfill. See Changing stream properties using manipulators.
Default: space.

    int ios::precision ()const
    Method

Report the number of significant digits currently in use for output of floating point numbers.
Default: 6.

    int ios::precision (int signif)
    Method

Set the number of significant digits (for input and output numeric conversions) to signif. You can also use the manipulator setprecision for this purpose. See Changing stream properties using manipulators.

    int ios::width ()const
    Method

Report the current output field width setting (the number of characters to write on the next << output operation).
Default: 0, which means to use as many characters as necessary.

    int ios::width (int num)
    Method

Set the input field width setting to num. Return the previous value for this stream. This value resets to zero (the default) every time you use <<; it is essentially an additional implicit argument to that operator. You can also use the manipulator setw for this purpose. See Changing stream properties using manipulators.

    fmtflags ios::flags ()const
    Method

Return the current value of the complete collection of flags controlling the format state. The following are the flags and their meanings when set.

- ios::dec
  ios::oct
  ios::hex
  Each of theses flags is for a numeric base to use in converting integers from internal to display representation, or vice versa: ios::dec, decimal, ios::oct, octal, or ios::hex, hexadecimal, respectively. (You can change the base using the manipulator setbase, or any of the manipulators dec, oct, or hex; see Changing stream properties using manipulators.)
  On input, if none of these flags is set, read numeric constants according to the prefix: decimal if no prefix (or a ’.’ suffix), octal if a 0 prefix is present, hexadecimal if a 0x prefix is present.
  Default: dec.
- ios::fixed
  Avoid scientific notation, and always show a fixed number of digits after the decimal point, according to the output precision in effect. Use ios::precision to set precision.
- ios::left
  ios::right
  ios::internal
  Where output is to appear in a fixed-width field: ios::left sets as left-justified, ios::right sets as right-justified, and ios::internal sets with padding in the middle (e.g., between a numeric sign and the associated value).
- ios::scientific
  Use scientific (exponential) notation to display numbers.
- ios::showbase
  Display the conventional prefix as a visual indicator of the conversion base: no prefix for decimal, 0 for octal, 0x for hexadecimal.
- ios::showpoint
  Display a decimal point followed by trailing zeros to fill out numeric fields, even when redundant.
- ios::showpos
  Display a positive sign on display of positive numbers.
- ios::skipws
  Skip white space. (On by default).
- ios::stdio
  Flush the C stdio streams stdout and stderr after each output operation (for programs that mix C and C++ output conventions).
- ios::unitbuf
  Flush after each output operation.
- ios::uppercase
  Use uppercase rather than lowercase characters in numeric displays; for instance, 0X7A rather than 0x7a, or 3.14E+09 rather than 3.14e+09.

    fmtflags ios::flags (fmtflags value)
    Method

Set value as the complete collection of flags controlling the format state. The flag values are described under ios::flags ().
Use ios::setf or ios::unsetf to change one property at a time.

    fmtflags ios::setf (fmtflags flag)
    Method

Set one particular flag (of those described for ios::flags(); return the complete collection of flags previously in effect. (Use ios::unsetf to cancel.)

    fmtflags ios::setf (fmtflags flag, fmtflags mask)
    Method

Clear the flag values indicated by mask, then set any of them that are also in flag. (Flag values are described for ios::flags ().) Return the complete collection of flags previously in effect. (See ios::unsetf for another way of clearing flags.)

    fmtflags ios::unsetf (fmtflags flag)
    Method

Make certain flag (a combination of flag values described for ios::flags ()) is not set for this stream; converse of ios::setf. Returns the old values of those flags.