money_put class template — Facet for output of monetary values
template <typename charT, typename OutputIterator = ostreambuf_iterator<charT> > class money_put : public locale::facet { public: typedef charT char_type; typedef OutputIterator iter_type; typedef basic_string<charT> string_type; explicit money_put(size_t refs = 0); iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, long double units) const; iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, const string_type& digits) const; static locale::id id; protected: virtual ~money_put( ); virtual iter_type do_put(iter_type, bool, ios_base&, char_type fill, long double units) const; virtual iter_type do_put(iter_type, bool, ios_base&, char_type fill, const string_type& digits) const; };
The money_put
class
template is a facet for formatting and printing monetary values. See
Example 13-27 (under
money_get
), which shows how to
use the money_put
facet. The
money_put<char>
and
money_put<wchar_t>
instantiations are standard.
As with other facets, the public members call virtual,
protected members with the same name prefaced by do_
. Thus, to use the facet, call the
public functions, such as put
,
which calls do_put
. The
descriptions below are for the virtual functions because they do the
real work. Imagine that for each virtual function description, there
is a corresponding description for a public, nonvirtual function,
such as:
iter_type
put
(iter_type
iter
, bool
intl,
ios_base&
stream
, char_type
fill
, long
double
units)
const
Returns do_put(iter
,
intl
, stream
, fill
, units)
The following are the virtual, protected members of money_put
:
virtual
iter_type
do_put
(iter_type
iter
, bool
intl,
ios_base&
stream
, char_type
fill
, long
double
units)
const
, virtual
iter_type
do_put
(iter_type
iter
, bool
intl,
ios_base&
stream
, char_type fill, const string_type&
digits)
const
Formats a monetary value and writes the formatted
characters to iter
. The
value to format is either an integer, units
, or a string of digit
characters in digits
. If
the first character of digits is widen('-')
, the remaining digits are
interpreted as a negative number.
The formatting pattern and punctuation characters are
obtained from the moneypunct
facet. For positive
values, pos_format( )
is
used; for negative values, neg_format( )
is used. The pattern
dictates the output format. (See moneypunct
later in this section for
information on patterns.) The currency symbol is printed only
if the showbase
flag is set
(that is, stream.flags( )
&
stream.showbase
is nonzero).
Thousands separators and a decimal point are inserted at the
appropriate places in the formatted output.
If necessary, fill
characters are inserted until the formatted width is stream.width( )
. The stream's
adjustfield
flag dictates
how fill characters are inserted. That is, stream.flags( )
&
stream.adjustfield
is tested, and if
it is equal to:
ios_base::internal
Fill characters are inserted where the pattern is
none
or space
.
ios_base::left
Fill characters are appended to the end of the formatted field.
Fill characters are inserted at the start of the formatted field.
Finally, stream.width(0)
is called to reset
the field width to 0
. The
return value is an iterator that points to one past the last
output character.