.\" ident @(#)num_put.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH num_put 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2num_put\fP \ - A numeric formatting facet for output. .SH SYNOPSIS .br #include .br template class num_put; .SH DESCRIPTION The num_put_facet allows for formatted output of numbers. basic_ostream and all other output-oriented streams use this facet to implement formatted numeric output. .SH INTERFACE .br template > .RE .RS 0 class num_put : public locale::facet { .br public: .RE .RS 1 typedef charT char_type; .br typedef OutputIterator iter_type; .br explicit num_put(size_t = 0); .RE .RS 0 .RE .RS 1 iter_type put(iter_type, ios_base&, char_type, bool) .RE .RS 11 const; .RE .RS 1 iter_type put(iter_type, ios_base&, char_type, long) .RE .RS 11 const; .RE .RS 1 iter_type put(iter_type, ios_base&, char_type, .RE .RS 15 unsigned long) const; .RE .RS 1 iter_type put(iter_type, ios_base&, char_type, .RE .RS 15 double) const; .RE .RS 1 iter_type put(iter_type, ios_base&, char_type, .RE .RS 15 long double) const; .RE .RS 1 static locale::id id; .RE .RS 0 .br protected: .RE .RS 2 ~num_put(); // virtual .RE .RS 1 virtual iter_type do_put(iter_type, ios_base&, char_type, .RE .RS 26 bool) const; .RE .RS 1 virtual iter_type do_put(iter_type, ios_base&, char_type, .RE .RS 26 long) const; .RE .RS 1 virtual iter_type do_put(iter_type, ios_base&, char_type, .RE .RS 26 unsigned long) const; .RE .RS 1 virtual iter_type do_put(iter_type, ios_base&, char_type, .RE .RS 26 double) const; .RE .RS 1 virtual iter_type do_put(iter_type, ios_base&, char_type, .RE .RS 26 long double) const; .RE .RS 0 }; .SH TYPES .br char_type .RE .RS 3 Type of character upon which the facet is instantiated. .RE .br iter_type .RE .RS 3 Type of iterator used to scan the character buffer. .RE .SH CONSTRUCTORS .br explicit num_put(size_t refs = 0) .RE .RS 3 Constructs a num_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. In this case, the object can be maintained across the lifetime of multiple locales. .RE .SH DESTRUCTORS .br ~num_put(); // virtual and protected .RE .RS 3 Destroys the facet. .RE .SH FACET ID .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 num_put facet include an interface to protected members. Each public member \f2xxx\fP has a corresponding virtual protected member \f2do_xxx\fP. All work is delegated to these protected members. For instance, the long version of the public \f2put\fP function simply calls its protected cousin \f2do_put\fP. .br iter_type .br put(iter_type s, ios_base& io, char_type fill, bool v) .RE .RS 3 const; .RE .RS 0 iter_type .br put(iter_type s, ios_base& io, char_type fill, long v) .RE .RS 3 const; .RE .RS 0 iter_type .br put(iter_type s, ios_base& io, char_type fill, .RE .RS 3 unsigned long v) const; .RE .RS 0 iter_type .br put(iter_type s, ios_base& io, char_type fill, double v) .RE .RS 3 const; .RE .RS 0 iter_type .br put(iter_type s, ios_base& io, char_type fill, .RE .RS 3 long double v) const; .RE .RS 3 Each of the five overloads of the \f2put\fP function simply call the corresponding \f2do_put\fP function. .RE .SH PROTECTED MEMBER FUNCTIONS .RE .RS 0 virtual iter_type .br do_put(iter_type s, ios_base& io, .RE .RS 6 char_type fill, bool v) const; .RE .RS 0 virtual iter_type .br do_put(iter_type s, ios_base& io, .RE .RS 6 char_type fill, long v) const; .RE .RS 0 virtual iter_type .br do_put(iter_type s, ios_base& io, .RE .RS 6 char_type fill,unsigned long) const; .RE .RS 0 virtual iter_type .br do_put(iter_type s, ios_base& io, .RE .RS 6 char_type fill, double v) const; .RE .RS 0 virtual iter_type .br do_put(iter_type s, ios_base& io, .RE .RS 6 char_type fill,long double v) const; .RE .RS 3 The five overloads of the \f2do_put\fP member function all take a numeric value and output a formatted character string representing that value. The character string is output through the \f2s\fP argument to the function. The \f2io\fP argument is used to obtain formatting specifications, and the \f2fill\fP argument determines the character to use in padding. .RE .SH EXAMPLE .RE .RS 0 // .br // numput.cpp .br // .br .br #include .br .br int main () .br { .RE .RS 1 using namespace std; .RE .RS 0 .RE .RS 1 typedef ostreambuf_iterator > .RE .RS 2 iter_type; .br .RE .RS 1 locale loc; .br bool bval = true; .br long lval = 422432L; .br unsigned long ulval = 12328889UL; .br double dval = 10933.8934; .br long double ldval = 100028933.8934; .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 num_put facet reference .RE .RS 1 const num_put& np = .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,(num_put*)0); .RE .RS 0 #endif .br .RE .RS 2 // Put out a bool .RE .RS 1 cout << bval << " --> "; .br np.put(begin,cout,' ',bval); .RE .RS 0 .RE .RS 2 // Put out a long .RE .RS 1 cout << endl << lval << " --> "; .br np.put(begin,cout,' ',lval); .RE .RS 0 .RE .RS 2 // Put out an unsigned long .RE .RS 1 cout << endl << ulval << " --> "; .br np.put(begin,cout,' ',ulval); .RE .RS 0 .RE .RS 2 // Put out a double .RE .RS 1 cout << endl << dval << " --> "; .br np.put(begin,cout,' ',dval); .RE .RS 0 .RE .RS 2 // Put out a long double .RE .RS 1 cout << endl << ldval << " --> "; .br np.put(begin,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, numget, numpunct, ctype