std::money_get<CharT,InputIt>::get,do_get (3) - Linux Manuals
std::money_get<CharT,InputIt>::get,do_get: std::money_get<CharT,InputIt>::get,do_get
NAME
std::money_get<CharT,InputIt>::get,do_get - std::money_get<CharT,InputIt>::get,do_get
Synopsis
Defined in header <locale>
public:
iter_type get(iter_type beg, iter_type end, bool intl, std::ios_base& str, (1)
std::ios_base::iostate& err, long double& units) const;
iter_type get(iter_type beg, iter_type end, bool intl, std::ios_base& str, (2)
std::ios_base::iostate& err, string_type& digits) const;
protected:
virtual iter_type do_get(iter_type beg, iter_type end, bool intl, std::ios_base& str, (3)
std::ios_base::iostate& err, long double& units) const;
virtual iter_type do_get(iter_type beg, iter_type end, bool intl, std::ios_base& str, (4)
std::ios_base::iostate& err, string_type& digits) const;
Parses monetary value from an input iterator and writes the result to a long double or string.
1-2) Public member functions, call the member function do_get of the most derived class.
3-4) Reads characters from the input iterator beg, expecting to find a monetary value formatted according to the rules specified by the std::ctype facet imbued in str.getloc() (ct for the rest of this page), the std::moneypunct<CharT, intl> facet imbued in str.getloc() (mp for the rest of this page), and the stream formatting flags obtained from str.flags().
If the input iterator beg becomes equal to end before the parsing was completed, sets both failbit and eofbit in err. If parsing fails for another reason, sets the failbit in err. Either way, does not modify the output parameter ((units or digits) on error.
If the parsing succeeds, does not change err, and stores the result in units or digits.
The formatting pattern used by this function is always mp.neg_format().
If mp.grouping() does not permit thousands separators, the first separator encountered is treated as a parsing error, otherwise they are treated as optional.
If money_base::space or money_base::none is the last element in the pattern, the parser does not attempt to consume any whitespace after the other components of the monetary value were parsed. Otherwise, one or more whitespace characters are consumed where money_base::space appears.
If showbase flag is set in str.flags(), the currency symbol or currency string is required, if it is not set, the currency symbol is optional.
If the first character of the string returned by mp.positive_sign() or mp.negative_sign() is found in the money_base::sign position of the formatting pattern, it is consumed, and the rest of the characters in that string are expected and consumed after all other components of the monetary value. If both mp.positive_sign() and mp.negative_sign() are non-empty, the sign is required and must match the first character of one of these strings. If one of theses strings is empty, the sign is optional (and if it is absent, the sign of the result corresponds to the string that was empty). If both strings are empty, or have the same first character, the result is given the positive sign. If the output parameter is a string (digits) and the result is negative, the value ct.widen('-') is stored as the first character of the result.
Digits from the input are extracted in order in which they appear and are placed in digits (after widening by ct.widen() as necessary), or into a temporary buffer buf1, from which the value of units is constructed as if by
(where n is the number of characters extracted from the input and stored in buf1 and buf2 is another sufficiently large character buffer)
Return value
An iterator pointing immediately after the last character recognized as a valid part of the monetary string input.
Notes
The currency units are assumed to be the smallest non-fractional units of the currency: cents in the U.S, yen in Japan. Thus, the input sequence "$1,056.23" in a U.S. locale produces the number 105623.0 in units or a string "105623" in digits
Because currency symbol is optional if showbase is off but the entire multicharacter negative_sign() is required, given the formatting pattern {sign, value, space, symbol} with showbase off and negative_sign of "-", the string "-1.23 €" parses as -123 and leaves "€" unconsumed on the input stream, but if negative_sign is "()", the string "(1.23 €)" is consumed completely.
The I/O manipulator std::get_money offers a simpler interface to this function.
Example
// Run this code