Go to the first, previous, next, last section, table of contents.

Choices in formatting

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

Method: char ios::fill () const

Report on the padding character in use.

Method: char ios::fill (char padding)

Set the padding character. You can also use the manipulator setfill. See section Changing stream properties using manipulators.

Default: blank.

Method: int ios::precision () const

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

Default: 6.

Method: int ios::precision (int signif)

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 section Changing stream properties using manipulators.

Method: int ios::width () const

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.

Method: int ios::width (int num)

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 section Changing stream properties using manipulators.

Method: fmtflags ios::flags () const

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

ios::dec
ios::oct
ios::hex
What numeric base to use in converting integers from internal to display representation, or vice versa: decimal, octal, or hexadecimal, respectively. (You can change the base using the manipulator setbase, or any of the manipulators dec, oct, or hex; see section 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; left-justified, right-justified, or with padding in the middle (e.g. between a numeric sign and the associated value), respectively.
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 and trailing zeros after it 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 upper-case characters for the non-numeral elements in numeric displays; for instance, `0X7A' rather than `0x7a', or `3.14E+09' rather than `3.14e+09'.

Method: fmtflags ios::flags (fmtflags value)

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.

Method: fmtflags ios::setf (fmtflags flag)

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

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

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.)

Method: fmtflags ios::unsetf (fmtflags flag)

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.


Go to the first, previous, next, last section, table of contents.