.\" ident @(#)money_put.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH money_put 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2money_put\fP \ - Monetary formatting facet for output. .SH SYNOPSIS .br #include .br template > .RE .RS 0 class money_put; .SH DESCRIPTION The money_put_facet takes a \f2long double\fP value, or generic sequence of digits and writes out a formatted representation of the monetary value. .SH INTERFACE .br template > .RE .RS 0 class money_put : public locale::facet { .br public: .RE .RS 1 typedef charT char_type; .br typedef OutputIterator iter_type; .br typedef basic_string string_type; .br explicit money_put(size_t = 0); .br iter_type put(iter_type, bool, ios_base&, char_type, .RE .RS 15 long double) const; .RE .RS 1 iter_type put(iter_type, bool, ios_base&, char_type, .RE .RS 15 const string_type&) const; .RE .RS 1 static locale::id id; .RE .RS 0 protected: .RE .RS 2 ~money_put(); // virtual .RE .RS 1 virtual iter_type do_put(iter_type, bool, ios_base&, .RE .RS 27 char_type, long double) const; .RE .RS 1 virtual iter_type do_put(iter_type, bool, ios_base&, .RE .RS 26 char_type, const string_type&) .br const; .RE .RS 0 }; .SH TYPES .br char_type .RE .RS 3 Type of the character upon which the facet is instantiated. .RE .br iter_type .RE .RS 3 Type of iterator used to scan the character buffer. .RE .br string_type .RE .RS 3 Type of character string passed to member functions. .RE .SH CONSTRUCTORS .br explicit money_put(size_t refs = 0) .RE .RS 3 Construct a money_put facet. If the \f2refs\fP argument is \f20\fP, then destruction of the object is delegated to the locale, or locales, containing it. This allows the user to ignore lifetime management issues. On the other hand, if \f2refs\fP is \f21\fP, then the object must be explicitly deleted; the locale does not do so. .RE .SH DESTRUCTORS .br ~money_put(); // virtual and protected .RE .RS 3 Destroys the facet. .RE .SH STATIC MEMBERS .br static locale::id id; .RE .RS 3 Unique identifier for this type of facet. .RE .SH PUBLIC MEMBER FUNCTIONS The public members of the money_put facet include an interface to protected members. Each public member \f2put\fP has a corresponding virtual protected member \f2do_put\fP. .br iter_type .br put(iter_type s, bool intl, ios_base& f, char_type fill, .RE .RS 3 long double units) const; .RE .RS 0 iter_type .br put(iter_type s, bool intl, ios_base& f, char_type fill, .RE .RS 3 const string_type& digits) const; .RE .RS 3 Each of these two overloads of the public member function \f2put\fP simply calls the corresponding protected \f2do_put\fP function. .RE .SH PROTECTED MEMBER FUNCTIONS .RE .RS 0 virtual iter_type .br do_put(iter_type s, bool intl, ios_base& f, char_type fill, .RE .RS 6 long double units) const; .RE .RS 3 Writes out a character string representation of the monetary value contained in \f2units\fP. Since \f2units\fP represents the monetary value in the smallest possible unit of currency, any fractional portions of the value are ignored. \f2f.flags()\fP and the \f2moneypunct\fP facet from \f2f.getloc()\fP give the formatting information. The \f2fill\fP argument is used for any padding. Returns an iterator pointing one past the last character written. .RE .RE .RS 0 virtual iter_type .br do_put(iter_type s, bool intl, ios_base& f, char_type fill, .RE .RS 6 const string_type& digits) const; .RE .RS 3 Writes out a character string representation of the monetary value contained in \f2digits\fP. \f2digits\fP represents the monetary value as a sequence of digits in the smallest possible unit of currency. \f2do_put\fP only looks at an optional \f2-\fP character and any immediately contiguous digits. \f2f.flags()\fP and the \f2moneypunct\fP facet from \f2f.getloc()\fP give the formatting information. The \f2fill\fP argument is used for any padding. Returns an iterator pointing one past the last character written. .RE .SH EXAMPLE .RE .RS 0 // .br // moneyput.cpp .br // .br .br #include .br #include .br .br int main () .br { .RE .RS 1 using namespace std; .RE .RS 0 .RE .RS 1 typedef ostreambuf_iterator > .RE .RS 9 iter_type; .RE .RS 0 .RE .RS 1 locale loc; .br string buffer("10002"); .br long double ldval = 10002; .RE .RS 0 .RE .RS 2 // Construct a ostreambuf_iterator on cout .RE .RS 1 iter_type begin(cout); .RE .RS 0 .RE .RS 2 // Get a money put facet .RE .RS 1 const money_put& mp = .RE .RS 0 #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE .RE .RS 1 use_facet >(loc); .RE .RS 0 #else .RE .RS 1 use_facet(loc,(money_put*)0); .RE .RS 0 #endif .br .RE .RS 2 // Put out the string representation of the monetary value .RE .RS 1 cout << buffer << " --> "; .br mp.put(begin,false,cout,' ',buffer); .RE .RS 0 .RE .RS 2 // Put out the long double representation .br // of the monetary value .RE .RS 1 cout << endl << ldval << " --> "; .br mp.put(begin,false,cout,' ',ldval); .RE .RS 0 .RE .RS 1 cout << endl; .RE .RS 0 .RE .RS 1 return 0; .RE .RS 0 } .SH SEE ALSO locale, facets, money_get, moneypunct