public member function
<locale>

std::money_get::get

numerical (1)
iter_type get (iter_type s, iter_type end, bool intl, ios_base& str,               ios_base::iostate& err, long double& units) const;
string (2)
iter_type get (iter_type s, iter_type end, bool intl, ios_base& str,               ios_base::iostate& err, string_type& digits) const;
Read monetary expression
Parses the sequence of characters between s and end for a monetary expression, and stores it into either units or digits.

The function reads characters until the character read cannot be part of a valid sequence in the format or end is reached. The next character after the last one processed by the function is pointed by the iterator returned by the function.

If successful, the first version (1) stores a floating-point value with the interpretation of the monetary expression in units. The second version (2) stores the digits extracted into digits as a basic_string object.

The function updates err with the error status if necessary:
value in errdescription
unchangedSuccess (without reaching end).
failbitFailure: The sequence did not match the expected format
eofbitend was reached during the operation (this can happen both in case of success or failure).

Internally, this function simply calls the virtual protected member do_get, which by default parses a monetary expression taking into account str's format flags. The function uses the locale selected in str to obtain format details (through facet moneypunct<char_type,intl>) and to map characters (through facet ctype<char_type>).

Parameters

s, end
Iterators pointing to the beginning and end characters of the sequence. The range used is [s,end), which contains all the characters between s and end, including the character pointed by s but not the character pointed by end.
Member type iter_type is the facet's iterator type (defined as an alias of money_get's second template parameter, InputIterator). By default, this is an istreambuf_iterator, allowing implicit conversions from basic_istream objects.
intl
true for international representation, false otherwise.
This is used to select the proper instatiation of moneypunct.
str
Object of a class derived from ios_base (generally an input stream object). It is only used to obtain formatting information.
err
Stream error state object, of type ios_base::iostate where the error states are stored when set.
units
The function stores in this variable the floating point value equivalent to the monetary expression read.
digits
The function stores in this variable a string value with the digits successfully extracted (only the digits, no punctuation marks).
Member type string_type is an instantiation of basic_string with the same character type as the facet (defined as an alias of basic_string<charT>, where charT is money_get's first template parameter).

Return value

The next character in the sequence right after where the extraction operation ended.
Member type iter_type is the facet's iterator type (defined as an alias of money_get's second template parameter, InputIterator).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// money_get example
#include <iostream>       // std::cin, std::cout, std::ios
#include <locale>         // std::locale, std::money_get, std::use_facet

int main ()
{
  std::locale loc("");    // default locale
  std::ios::iostate state;
  long double price;

  std::cout << "Please, enter the price: ";
  std::use_facet<std::money_get<char> >(loc).get
    (std::cin, std::money_get<char>::iter_type(), false, std::cin, state, price);

  if ((state & std::ios::failbit)==std::ios::failbit)
    std::cout << "ERROR: failed to read price\n";
  else
    std::cout << "The price of three items is " << (price*3.0) << '\n';

  return 0;
}

Possible output:

Please, enter the price: $12.95
ERROR: failed to read price

The default locale failed to interpret the format of the price entered.

Data races

The object, and up to the entire range between s and end, are accessed.
Arguments str, err and units/digits may be modified.

Exception safety

If an exception is thrown, there are no changes in the facet object, although some of arguments may have been affected.

See also