Name

money_get class template — Facet for input of monetary values

Synopsis

template <typename charT, 
          typename 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 refs = 0);
  iter_type get(iter_type s, iter_type end, bool intl, ios_base& f, 
                ios_base::iostate& err, long double& units) const;
  iter_type get(iter_type s, iter_type end, bool intl, ios_base& f, 
                ios_base::iostate& err, string_type& digits) const;
  static locale::id id;
protected:
  virtual ~money_get(  );
  virtual iter_type do_get(iter_type begin, iter_type end, bool intl, 
                           ios_base& strean, ios_base::iostate& err,
                           long double& units) const;|  virtual iter_type 
                    do_get(iter_type begin, iter_type end, bool intl, 
                           ios_base& stream, ios_base::iostate& err,
                           string_type& digits) const;
};

The money_get class template is a facet for parsing monetary values from an input stream. The money_get<char> and money_get<wchar_t> instantiations are standard. Example 13-27 shows a simple use of money_get and money_put.

Example

Example 13-27. Reading and writing monetary values
#include <iostream> #include <locale> #include <ostream> int main( ) { std::ios_base::iostate err = std::ios_base::goodbit; long double value; std::cout << "What is your hourly wage? "; std::use_facet<std::money_get<char> >(std::locale( )).get( std::cin, std::istreambuf_iterator<char>( ), false, std::cin, err, value); ...

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.