Click on the banner to return to the class reference home page.

money_put


money_putlocale::facet

Summary

Monetary formatting facet for output.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <locale>
template <class charT, bool Intl = false,
          class OutputIterator = ostreambuf_iterator<charT> >
class money_put;

Description

The money_put facet takes a long double value, or generic sequence of digits and writes out a formatted representation of the monetary value.

Interface

template <class charT, bool Intl = false,
          class 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 = 0);
  iter_type put(iter_type, ios_base&, char_type,
                long double) const;
  iter_type put(iter_type, ios_base&, char_type,
                const string_type&) const;
  static const bool intl = Intl;
  static locale::id id;
protected:
  ~money_put();  // virtual
  virtual iter_type  do_put(iter_type, ios_base&, char_type, 
                            long double) const;
  virtual iter_type do_put(iter_type, ios_base&, char_type,
                           const string_type&) const;
}; 

Types

char_type
iter_type
string_type

Constructors and Destructors

explicit money_put(size_t refs = 0)





~money_put();  // virtual and protected

Static Members

static locale::id id;
static const bool intl = Intl;

Public Member Functions

The public members of the money_put facet provide an interface to protected members. Each public member put has a corresponding virtual protected member do_put.

iter_type
put(iter_type s, ios_base& f, char_type fill,
    long double units) const;
iter_type 
put(iter_type s, ios_base& f, char_type fill,
    const string_type& digits) const;




Protected Member Functions

virtual iter_type
do_put(iter_type s, ios_base& f, char_type fill, 
       long double units) const;




virtual iter_type 
do_put(iter_type s, ios_base& f, char_type fill,
       const string_type& digits) const;




Example

//
// moneyput.cpp
//

#include <string>
#include <iostream>

int main ()
{
  using namespace std;

  typedef ostreambuf_iterator<char,char_traits<char> > iter_type;
  
  locale loc;
  string buffer("10002");
  long double ldval = 10002; 

  // Construct a ostreambuf_iterator on cout
  iter_type begin(cout);

  // Get a money put facet
  const money_put<char,false,iter_type>& mp = 
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  use_facet<money_put<char,false,iter_type> >(loc);
#else
  use_facet(loc,(money_put<char,false,iter_type>*)0);
#endif

  // Put out the string representation of the monetary value
  cout << buffer << " --> ";
  mp.put(begin,cout,' ',buffer);

  // Put out the long double representation 
  // of the monetary value
  cout << endl << ldval << " --> ";
  mp.put(begin,cout,' ',ldval);

  cout <<  endl;

  return 0;
}

See Also

locale, facets, money_get, moneypunct


©Copyright 1996, Rogue Wave Software, Inc.