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

money_get


money_getlocale::facet

Summary

Monetary formatting facet for input.

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

Synopsis

#include <locale>
template <class charT, bool Intl = false,
          class InputIterator = istreambuf_iterator<charT> >
class money_get;

Description

The money_get facet interprets formatted monetary string values. The Intl template parameter is used to specify locale or international formatting. If Intl is true then international formatting is used, otherwise locale formatting is used.

Interface

template <class charT, bool Intl = false,
          class InputIterator = istreambuf_iterator<charT> >
class money_get : public locale::facet {
public:
  typedef charT               char_type;
  typedef InputIterator       iter_type;
  typedef basic_string<charT> string_type;
  explicit money_get(size_t = 0);
  iter_type get(iter_type, iter_type, ios_base&,
                ios_base::iostate&, long double&) const;
  iter_type get(iter_type, iter_type, ios_base&,
                ios_base::iostate&, string_type&) const;
  static const bool intl = Intl;
  static locale::id id;
protected:
  ~money_get();  // virtual
  virtual iter_type do_get(iter_type, iter_type, ios_base&,
                           ios_base::iostate&, 
                           long double&) const;
  virtual iter_type do_get(iter_type, iter_type, ios_base&,
                           ios_base::iostate&, 
                           string_type&) const;
}; 

Types

char_type
iter_type
string_type

Constructors and Destructors

explicit money_get(size_t refs = 0)
~money_get();  // virtual and protected

Static Members

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

Public Member Functions

The public members of the money_get facet provide an interface to protected members. Each public member get has a corresponding virtual protected member do_get.

iter_type 
get(iter_type s, iter_type end, ios_base& f,
    ios_base::iostate& err, long double& units) const;
iter_type 
get(iter_type s, iter_type end, ios_base& f,
    ios_base::iostate& err, string_type& digits) const;

Protected Member Functions

virtual iter_type 
do_get(iter_type s, iter_type end,
       ios_base& f,
       ios_base::iostate& err, 
       long double& units) const;
virtual iter_type 
do_get(iter_type s, iter_type end, 
       ios_base& f,
       ios_base::iostate& err, 
       string_type& digits) const;

Example

//
// moneyget.cpp
//

#include <string>
#include <sstream>

int main ()
{
  using namespace std;
  typedef istreambuf_iterator<char,char_traits<char> > iter_type;
  
  locale loc;
  string buffer("$100.02");
  string dest;
  long double ldest;
  ios_base::iostate state;
  iter_type end;

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

  {
    // Build an istringstream from the buffer and construct
    // a beginning iterator on it.
    istringstream ins(buffer);
    iter_type begin(ins);

    // Get a string representation of the monetary value
    mgf.get(begin,end,ins,state,dest);
  }
  {
    // Build another istringstream from the buffer, etc.
    // so we have an iterator pointing to the beginning
    istringstream ins(buffer);
    iter_type begin(ins);

    // Get a long double representation 
    // of the monetary value
    mgf.get(begin,end,ins,state,ldest);
  }
  cout << buffer << " --> " << dest 
       << " --> " << ldest << endl;

  return 0;
}

See Also

locale, facets, money_put, moneypunct


©Copyright 1996, Rogue Wave Software, Inc.