cerr are instances
ostream class. They map to the Unix standard
output and standard error devices, respectively. (The less used
clog is also an instance of this class.) The format of numbers
written to these devices can be controlled through the methods and
constants of this class.
In the following example we read a table of and values and write it out with a fixed decimal point, with four digits past the decimal, and with right-justification in a column of width seven characters for each value.
precision(int)method sets the number of digits past the decimal point for fixed decimal format or the total number of digits for scientific notation. It remains in force until called again.
flags(...) method determines the justification and
notation. The constants are in the
ios namespace. Use
the vertical bar
| (bitwise logical ``or'') to combine options.
The obvious choices for justification are
right. The common choices for notation are
for fixed decimal point and
scientific for scientific
notation. This setting remains in force until you call the
flags method again with new values.
Here is a longer list of ios constants:
|floatfield||either fixed or scientific|
e. The default value is
floatfield, meaning whichever fits better. To combine compatible choices, simply add them, as we have done.
width(int) method must be called for each value. It
determines the number of characters allocated to the number. The
value is really a lower bound. If the number does not fit the
requested space, the width request is ignored.