Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/moneypunct"

From cppreference.com
< cpp‎ | locale
m (Text replace - "{{tdcl list end" to "{{dcl list end")
m (fmt)
 
(22 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{cpp/title | moneypunct}}
+
{{cpp/title|moneypunct}}
{{cpp/locale/moneypunct/sidebar}}
+
{{cpp/locale/moneypunct/navbar}}
{{ddcl list begin}}
+
{{dcl begin}}
{{ddcl list header | locale}}
+
{{dcl header|locale}}
{{ddcl list item | 1=
+
{{dcl|1=
template< class charT, bool International = false >
+
template< class CharT, bool International = false >
class moneypunct : public std::locale::facet, public std::money_base;
+
class moneypunct;
 
}}
 
}}
{{ddcl list end}}
+
{{dcl end}}
  
The facet {{c|std::moneypunct}} encapsulates monetary value format preferences. Stream I/O manipulators {{c|std::get_money}} and {{c|std::put_money}} use {{c|std::moneypunct}} through {{c|std::money_get}} and {{c|std::money_put}} for parsing monetary value input and formatting monetary value output.  
+
The facet {{tt|std::moneypunct}} encapsulates monetary value format preferences. Stream I/O manipulators {{lc|std::get_money}} and {{lc|std::put_money}} use {{tt|std::moneypunct}} through {{lc|std::money_get}} and {{lc|std::money_put}} for parsing monetary value input and formatting monetary value output.  
  
Four specializations are provided by the standard library
+
{{inheritance diagram/std-moneypunct}}
  
{{dcl list begin}}
+
===Specializations===
{{tdcl list header | locale }}
+
The standard library is guaranteed to provide the following specializations (they are {{rlp|locale|required to be implemented by any locale object}}):
{{tdcl list item | {{c|std::moneypunct<char>}}         | provides equivalents of the "C" locale preferences }}
+
{{dsc begin}}
{{tdcl list item | {{c|std::moneypunct<wchar_t>}}       | provides wide character equivalents of the "C" locale preferences }}
+
{{dsc header|locale}}
{{tdcl list item | {{c|std::moneypunct<char, true>}}   | provides equivalents of the "C" locale preferences, with international currency symbols }}
+
{{dsc|{{c/core|std::moneypunct<char>}}|provides equivalents of the "C" locale preferences}}
{{tdcl list item | {{c|std::moneypunct<wchar_t, true>}} | provides wide character equivalents of the "C" locale preferences, with international currency symbols }}
+
{{dsc|{{c/core|std::moneypunct<wchar_t>}}|provides wide character equivalents of the "C" locale preferences}}
{{dcl list end}}
+
{{dsc|{{c/core|std::moneypunct<char, true>}}|provides equivalents of the "C" locale preferences, with international currency symbols}}
 +
{{dsc|{{c/core|std::moneypunct<wchar_t, true>}}|provides wide character equivalents of the "C" locale preferences, with international currency symbols}}
 +
{{dsc end}}
  
 
===Member types===
 
===Member types===
{{dcl list begin}}
+
{{dsc begin}}
{{tdcl list hitem | Member type | Definition}}
+
{{dsc hitem|Member type|Definition}}
{{tdcl list item | {{tt|char_type}} | {{tt|charT}}}}
+
{{dsc|{{tt|char_type}}|{{tt|CharT}}}}
{{tdcl list item | {{tt|string_type}} | {{c|std::basic_string<charT>}}}}
+
{{dsc|{{tt|string_type}}|{{c/core|std::basic_string<CharT>}}}}
{{dcl list end}}
+
{{dsc end}}
 
+
===Member constants===
+
{{dcl list begin}}
+
{{tdcl list hitem | Member | Definition}}
+
{{tdcl list item | {{dcl small|const bool}} {{tt|intl}} {{mark|static}} | {{tt|International}} }}
+
{{dcl list end}}
+
 
+
===Member objects===
+
{{dcl list begin}}
+
{{tdcl list hitem | Member | Type}}
+
{{tdcl list item | {{tt|id}} {{mark|static}} | {{c|std::locale::id}} }}
+
{{dcl list end}}
+
  
 
===Member functions===
 
===Member functions===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list mem ctor      | cpp/locale/moneypunct/moneypunct  | constructs a new moneypunct facet }}
+
{{dsc inc|cpp/locale/moneypunct/dsc constructor}}
{{dcl list prot mem dtor | cpp/locale/moneypunct/~moneypunct | destructs a moneypunct facet }}
+
{{dsc inc|cpp/locale/moneypunct/dsc decimal_point}}
{{dcl list h2 |  }}
+
{{dsc inc|cpp/locale/moneypunct/dsc thousands_sep}}
{{dcl list mem fun | cpp/locale/moneypunct/do_decimal_point | title=decimal_point | invokes {{tt|do_decimal_point}}  }}
+
{{dsc inc|cpp/locale/moneypunct/dsc grouping}}
{{dcl list mem fun | cpp/locale/moneypunct/do_thousands_sep | title=thousands_sep | invokes {{tt|do_thousands_sep}} }}
+
{{dsc inc|cpp/locale/moneypunct/dsc curr_symbol}}
{{dcl list mem fun | cpp/locale/moneypunct/do_grouping | title=grouping | invokes {{tt|do_grouping}} }}
+
{{dsc inc|cpp/locale/moneypunct/dsc positive_sign}}
{{dcl list mem fun | cpp/locale/moneypunct/do_curr_symbol | title=curr_symbol | invokes {{tt|do_curr_symbol}} }}
+
{{dsc inc|cpp/locale/moneypunct/dsc frac_digits}}
{{dcl list mem fun | cpp/locale/moneypunct/do_positive_sign | title=positive_sign | invokes {{tt|do_positive_sign}} }}
+
{{dsc inc|cpp/locale/moneypunct/dsc pos_format}}
{{dcl list mem fun | cpp/locale/moneypunct/do_negative_sign | title=negative_sign | invokes {{tt|do_negative_sign}} }}
+
{{dsc end}}
{{dcl list mem fun | cpp/locale/moneypunct/do_frac_digits | title=frac_digits | invokes {{tt|do_frac_digits}} }}
+
{{dcl list mem fun | cpp/locale/moneypunct/do_pos_format | title=pos_format | invokes {{tt|do_pos_format}} }}
+
{{dcl list mem fun | cpp/locale/moneypunct/do_neg_format | title=neg_format | invokes {{tt|do_neg_format}} }}
+
{{dcl list end}}
+
  
 
===Protected member functions===
 
===Protected member functions===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list prot mem vfun | cpp/locale/moneypunct/do_decimal_point | provides the character to use as decimal point}}
+
{{dsc inc|cpp/locale/moneypunct/dsc destructor}}
{{dcl list prot mem vfun | cpp/locale/moneypunct/do_thousands_sep | provides the character to use as thousands separator}}
+
{{dsc inc|cpp/locale/moneypunct/dsc do_decimal_point}}
{{dcl list prot mem vfun | cpp/locale/moneypunct/do_grouping      | provides the numbers of digits between each pair of thousands separators}}
+
{{dsc inc|cpp/locale/moneypunct/dsc do_thousands_sep}}
{{dcl list prot mem vfun | cpp/locale/moneypunct/do_curr_symbol  | provides the string to use as the currency identifier}}
+
{{dsc inc|cpp/locale/moneypunct/dsc do_grouping}}
{{dcl list prot mem vfun | cpp/locale/moneypunct/do_positive_sign | provides the string to indicate a positive value}}
+
{{dsc inc|cpp/locale/moneypunct/dsc do_curr_symbol}}
{{dcl list prot mem vfun | cpp/locale/moneypunct/do_negative_sign | provides the string to indicate a negative value}}
+
{{dsc inc|cpp/locale/moneypunct/dsc do_positive_sign}}
{{dcl list prot mem vfun | cpp/locale/moneypunct/do_frac_digits   | provides the number of digits to display after the decimal point}}
+
{{dsc inc|cpp/locale/moneypunct/dsc do_frac_digits}}
{{dcl list prot mem vfun | cpp/locale/moneypunct/do_pos_format   | provides the formatting pattern for positive values}}
+
{{dsc inc|cpp/locale/moneypunct/dsc do_pos_format}}
{{dcl list prot mem vfun | cpp/locale/moneypunct/do_neg_format    | provides the formatting pattern for negative values}}
+
{{dsc end}}
{{dcl list end}}
+
  
{{ inherited | {{small|std::}}money_base |
+
===Member constants===
{{dcl list begin}}
+
{{dsc begin}}
{{tdcl list hitem | Member type | Definition}}
+
{{dsc hitem|Member|Definition}}
{{tdcl list item | {{c|enum part { none, space, symbol, sign, value };}} | unscoped enumeration type}}
+
{{dsc|{{dsc small|const bool}} {{tt|intl}} {{mark|static}}|{{tt|International}}}}
{{tdcl list item | {{c|struct pattern { char field[4]; };}} | the monetary format type}}
+
{{dsc end}}
{{dcl list end}}
+
  
{{dcl list begin}}
+
===Member objects===
{{tdcl list hitem | Enumeration constant | Definition}}
+
{{dsc begin}}
{{tdcl list item | {{tt|none}}    | whitespace is permitted but not required except in the last position, where whitespace is not permitted}}
+
{{dsc mem obj|nolink=true|{{dsc small|static std::locale::id}} id|''id'' of the locale}}
{{tdcl list item | {{tt|space}}    | one or more whitespace characters are required}}
+
{{dsc end}}
{{tdcl list item | {{tt|symbol}}  | the sequence of characters returned by moneypunct::curr_symbol is required}}
+
{{tdcl list item | {{tt|sign}}    | the first of the characters returned by moneypunct::positive_sign or moneypunct::negative_sign is required}}
+
{{tdcl list item | {{tt|value}}    | the absolute numeric monetary value is required}}
+
{{dcl list end}}
+
}}
+
  
===Example===
+
{{include|cpp/locale/money_base/inherit}}
  
{{example
+
===See also===
|  
+
{{dsc begin}}
| code=
+
{{dsc inc|cpp/locale/dsc money_base}}
#include <iostream>
+
{{dsc inc|cpp/locale/dsc moneypunct_byname}}
#include <locale>
+
{{dsc inc|cpp/locale/dsc money_get}}
int main()
+
{{dsc inc|cpp/locale/dsc money_put}}
{
+
{{dsc end}}
    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===
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
{{dcl list begin}}
+
{{dcl list template | cpp/locale/dcl list money_base}}
+
{{dcl list template | cpp/locale/dcl list moneypunct_byname}}
+
{{dcl list template | cpp/locale/dcl list money_get}}
+
{{dcl list template | cpp/locale/dcl list money_put}}
+
{{dcl list end}}
+

Latest revision as of 01:27, 13 December 2023

 
 
 
 
Defined in header <locale>
template< class CharT, bool International = false >
class moneypunct;

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

Contents

[edit] Specializations

The standard library is guaranteed to provide the following specializations (they are required to be implemented by any locale object):

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

[edit] Member types

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

[edit] Member functions

constructs a new moneypunct facet
(public member function) [edit]
invokes do_decimal_point
(public member function) [edit]
invokes do_thousands_sep
(public member function) [edit]
invokes do_grouping
(public member function) [edit]
invokes do_curr_symbol
(public member function) [edit]
invokes do_positive_sign or do_negative_sign
(public member function) [edit]
invokes do_frac_digits
(public member function) [edit]
invokes do_pos_format/do_neg_format
(public member function) [edit]

[edit] Protected member functions

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

[edit] Member constants

Member Definition
const bool intl (static) International

[edit] Member objects

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

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 std::moneypunct::curr_symbol is required
sign the first of the characters returned by std::moneypunct::positive_sign or std::moneypunct::negative_sign is required
value the absolute numeric monetary value is required

[edit] See also

defines monetary formatting patterns
(class) [edit]
represents the system-supplied std::moneypunct for the named locale
(class template) [edit]
parses and constructs a monetary value from an input character sequence
(class template) [edit]
formats a monetary value for output as a character sequence
(class template) [edit]