num_put (3C++std) - Tru64 UNIX
Standard C++ LibraryCopyright 1996, Rogue Wave Software, Inc. NAME
num_put - Numeric formatting facet for output.
SYNOPSIS
#include <locale>
template <class charT, class OutputIterator> class num_put;
DESCRIPTION
The num_put<charT,OutputIterator> template provides facilities for
formatted output of numbers. basic_ostream and all other input oriented
streams use this facet to implement formatted numeric output.
INTERFACE
template <class charT, class OutputIterator = ostreambuf_iterator<charT> >
class num_put : public locale::facet {
public:
typedef charT char_type;
typedef OutputIterator iter_type;
explicit num_put(size_t = 0);
iter_type put(iter_type, ios_base&, char_type, bool) const;
iter_type put(iter_type, ios_base&, char_type, long) const;
iter_type put(iter_type, ios_base&, char_type,
unsigned long) const;
iter_type put(iter_type, ios_base&, char_type,
double) const;
iter_type put(iter_type, ios_base&, char_type,
long double) const;
static locale::id id;
protected:
~num_put(); // virtual
virtual iter_type do_put(iter_type, ios_base&, char_type,
bool) const;
virtual iter_type do_put(iter_type, ios_base&, char_type,
long) const;
virtual iter_type do_put(iter_type, ios_base&, char_type,
unsigned long) const;
virtual iter_type do_put(iter_type, ios_base&, char_type,
double) const;
virtual iter_type do_put(iter_type, ios_base&, char_type,
long double) const;
};
TYPES
char_type
Type of character upon which the facet is instantiated.
iter_type
Type of iterator used to scan the character buffer.
CONSTRUCTORS AND DESTRUCTORS
explicit num_put(size_t refs = 0)
Construct a num_put facet. If the refs argument is 0 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
had, if refs is 1 then the object must be explicitly deleted; the
locale will not do so. In this case, the object can be maintained
across the lifetime of multiple locales.
~num_put(); // virtual and protected
Destroy the facet
FACET ID
static locale::id id;
Unique identifier for this type of facet.
PUBLIC MEMBER FUNCTIONS
The public members of the num_put facet provide an interface to protected
members. Each public member xxx has a corresponding virtual protected
member do_xxx. All work is delagated to these protected members. For
instance, the long version of the public put function simply calls its
protected cousin do_put.
iter_type
put(iter_type s, ios_base& io, char_type fill, bool v) const;
iter_type
put(iter_type s, ios_base& io, char_type fill, long v) const;
iter_type
put(iter_type s, ios_base& io, char_type fill,
unsigned long v) const;
iter_type
put(iter_type s, ios_base& io, char_type fill, double v) const;
iter_type
put(iter_type s, ios_base& io, char_type fill, long double v) const;
Each of the five overloads of the put function simply call the
corresponding do_put function.
PROTECTED MEMBER FUNCTIONS
virtual iter_type
do_put(iter_type s, ios_base& io,
char_type fill, bool v) const;
virtual iter_type
do_put(iter_type s, ios_base& io,
char_type fill, long v) const;
virtual iter_type
do_put(iter_type s, ios_base& io,
char_type fill,unsigned long) const;
virtual iter_type
do_put(iter_type s, ios_base& io,
char_type fill, double v) const;
virtual iter_type
do_put(iter_type s, ios_base& io,
char_type fill,long double v) const;
The five overloads of the do_put member function all take a numeric
value and output a formatted character string representing that value.
The character string is output through the s argument to the function.
The io argument is used to obtain formatting specifications, and the
fill argument determines the character to use in padding.
EXAMPLE
//
// numput.cpp
//
#include <iostream>
int main ()
{
using namespace std;
typedef ostreambuf_iterator<char,char_traits<char> > iter_type;
locale loc;
bool bval = true;
long lval = 422432L;
unsigned long ulval = 12328889UL;
double dval = 10933.8934;
long double ldval = 100028933.8934;
// Construct a ostreambuf_iterator on cout
iter_type begin(cout);
// Get a num_put facet reference
const num_put<char,iter_type>& np =
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
use_facet<num_put<char,iter_type> >(loc);
#else
use_facet(loc,(num_put<char,iter_type>*)0);
#endif
// Put out a bool
cout << bval << " --> ";
np.put(begin,cout,' ',bval);
// Put out a long
cout << endl << lval << " --> ";
np.put(begin,cout,' ',lval);
// Put out an unsigned long
cout << endl << ulval << " --> ";
np.put(begin,cout,' ',ulval);
// Put out a double
cout << endl << dval << " --> ";
np.put(begin,cout,' ',dval);
// Put out a long double
cout << endl << ldval << " --> ";
np.put(begin,cout,' ',ldval);
cout << endl;
return 0;
}
SEE ALSO
locale, facets, numget, numpunct, ctype
STANDARDS CONFORMANCE
ANSI X3J16/ISO WG21 Joint C++ Committee
|