Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/moneypunct"

From cppreference.com
< cpp‎ | locale
(+inheritance diagram; fix declaration)
(fmt)
Line 28: Line 28:
 
{{dcl list item | {{tt|char_type}} | {{tt|charT}}}}
 
{{dcl list item | {{tt|char_type}} | {{tt|charT}}}}
 
{{dcl list item | {{tt|string_type}} | {{c|std::basic_string<charT>}}}}
 
{{dcl list item | {{tt|string_type}} | {{c|std::basic_string<charT>}}}}
{{dcl list end}}
 
 
===Member constants===
 
{{dcl list begin}}
 
{{dcl list hitem | Member | Definition}}
 
{{dcl list item | {{dcl small|const bool}} {{tt|intl}} {{mark|static}} | {{tt|International}} }}
 
{{dcl list end}}
 
 
===Member objects===
 
{{dcl list begin}}
 
{{dcl list hitem | Member | Type}}
 
{{dcl list item | {{tt|id}} {{mark|static}} | {{c|std::locale::id}} }}
 
 
{{dcl list end}}
 
{{dcl list end}}
  
Line 87: Line 75:
 
{{dcl list end}}
 
{{dcl list end}}
 
}}
 
}}
 +
 +
===Member constants===
 +
{{dcl list begin}}
 +
{{dcl list hitem | Member | Definition}}
 +
{{dcl list item | {{dcl small|const bool}} {{tt|intl}} {{mark|static}} | {{tt|International}} }}
 +
{{dcl list end}}
 +
 +
===Member objects===
 +
{{dcl list begin}}
 +
{{dcl list mem obj | nolink=true | {{dcl small|static std::locale::id}} id | ''id'' of the locale }}
 +
{{dcl list end}}
  
 
===Example===
 
===Example===

Revision as of 07:00, 23 September 2012

 
 
 
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
template< class CharT, bool International = false >
class moneypunct;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

The facet std::moneypunct encapsulates monetary value format preferences. Stream I/O manipulators std::get_money and std::put_money use std::moneypunct through std::money_get and std::money_put for parsing monetary value input and formatting monetary value output.

cpp/locale/money basecpp/locale/locale/facetstd-moneypunct-inheritance.svg

Inheritance diagram

Four specializations are provided by the standard library

Defined in header <locale>
std::moneypunct<char> provides equivalents of the "C" locale preferences
std::moneypunct<wchar_t> provides wide character equivalents of the "C" locale preferences
std::moneypunct<char, true> provides equivalents of the "C" locale preferences, with international currency symbols
std::moneypunct<wchar_t, true> provides wide character equivalents of the "C" locale preferences, with international currency symbols

Contents

Member types

Member type Definition
char_type charT
string_type std::basic_string<charT>

Member functions

constructs a new moneypunct facet
(public member function)
destructs a moneypunct facet
(protected member function)
invokes do_decimal_point
(public member function)
invokes do_thousands_sep
(public member function)
invokes do_grouping
(public member function)
invokes do_curr_symbol
(public member function)
invokes do_positive_sign
(public member function)
invokes do_negative_sign
(public member function)
invokes do_frac_digits
(public member function)
invokes do_pos_format
(public member function)
invokes do_neg_format
(public member function)

Protected member functions

provides the character to use as decimal point
(virtual protected member function)
provides the character to use as thousands separator
(virtual protected member function)
[virtual]
provides the numbers of digits between each pair of thousands separators
(virtual protected member function)
provides the string to use as the currency identifier
(virtual protected member function)
provides the string to indicate a positive value
(virtual protected member function)
provides the string to indicate a negative value
(virtual protected member function)
provides the number of digits to display after the decimal point
(virtual protected member function)
provides the formatting pattern for positive values
(virtual protected member function)
provides the formatting pattern for negative values
(virtual protected member function)

Inherited from std::money_base

Member type Definition
enum part { none, space, symbol, sign, value }; unscoped enumeration type
struct pattern { char field[4]; }; the monetary format type
Enumeration constant Definition
none whitespace is permitted but not required except in the last position, where whitespace is not permitted
space one or more whitespace characters are required
symbol the sequence of characters returned by moneypunct::curr_symbol is required
sign the first of the characters returned by moneypunct::positive_sign or moneypunct::negative_sign is required
value the absolute numeric monetary value is required

Member constants

Member Definition
const bool intl (static) International

Member objects

static std::locale::id id
id of the locale
(public member object)

Example

#include <iostream>
#include <locale>
int main()
{
    std::locale jp("ja_JP.UTF-8");
    std::cout << "japanese currency symbol is "
              << std::use_facet<std::moneypunct<char, true>>(jp).curr_symbol()
              << "or "
              << std::use_facet<std::moneypunct<char>>(jp).curr_symbol()
              << " for short\n";
}

Output:

japanese currency symbol is JPY or ¥ for short

See also

Template:cpp/locale/dcl list money baseTemplate:cpp/locale/dcl list moneypunct bynameTemplate:cpp/locale/dcl list money getTemplate:cpp/locale/dcl list money put