##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::moneypunct_byname

From cppreference.com
< cpp‎ | locale

Defined in header `<locale>` |  |
template< class CharT, bool Intl = false > class moneypunct_byname : public std::moneypunct<CharT, Intl>; |  |

std::moneypunct_byname is a std::moneypunct facet which encapsulates monetary formatting preferences of a locale specified at its construction.

Two specializations are provided by the standard library

Defined in header `<locale>`
std::moneypunct_byname<char, Intl> | locale-specific std::moneypunct facet for narrow character I/O
std::moneypunct_byname<wchar_t, Intl> | locale-specific std::moneypunct facet for wide character I/O

### [edit] Member types

Member type | Definition
`pattern` | std::money_base::pattern
`string_type` | std::basic_string<CharT>

### [edit] Member functions

(constructor) | constructs a new `moneypunct_byname` facet (public member function) [edit]
(destructor) | destroys a `moneypunct_byname` facet (protected member function) [edit]

[edit]

# std::moneypunct_byname::moneypunct_byname

explicit moneypunct_byname( const char* name, std::size_t refs = 0 ); |  |
explicit moneypunct_byname( const std::string& name, std::size_t refs = 0 ); |  | (since C++11)

Constructs a new `std::moneypunct_byname` facet for a locale with `name`.

`refs` is used for resource management: if refs == 0, the implementation destroys the facet, when the last std::locale object holding it is destroyed. Otherwise, the object is not destroyed.

### Parameters

name | - | the name of the locale
refs | - | the number of references that link to the facet

[edit]

# std::moneypunct_byname::~moneypunct_byname

protected: ~moneypunct_byname(); |  |

Destroys the facet.

[edit]

## Inherited from std::moneypunct

### Member types

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

### Member functions

decimal_point | invokes `do_decimal_point` (public member function of `std::moneypunct`) [edit]
thousands_sep | invokes `do_thousands_sep` (public member function of `std::moneypunct`) [edit]
grouping | invokes `do_grouping` (public member function of `std::moneypunct`) [edit]
curr_symbol | invokes `do_curr_symbol` (public member function of `std::moneypunct`) [edit]
positive_sign negative_sign | invokes `do_positive_sign` or `do_negative_sign` (public member function of `std::moneypunct`) [edit]
frac_digits | invokes `do_frac_digits` (public member function of `std::moneypunct`) [edit]
pos_format neg_format | invokes `do_pos_format`/`do_neg_format` (public member function of `std::moneypunct`) [edit]

### Protected member functions

do_decimal_point [virtual] | provides the character to use as decimal point (virtual protected member function of `std::moneypunct`) [edit]
do_thousands_sep [virtual] | provides the character to use as thousands separator (virtual protected member function of `std::moneypunct`) [edit]
do_grouping [virtual] | provides the numbers of digits between each pair of thousands separators (virtual protected member function of `std::moneypunct`) [edit]
do_curr_symbol [virtual] | provides the string to use as the currency identifier (virtual protected member function of `std::moneypunct`) [edit]
do_positive_sign do_negative_sign [virtual] | provides the string to indicate a positive or negative value (virtual protected member function of `std::moneypunct`) [edit]
do_frac_digits [virtual] | provides the number of digits to display after the decimal point (virtual protected member function of `std::moneypunct`) [edit]
do_pos_format do_neg_format [virtual] | provides the formatting pattern for currency values (virtual protected member function of `std::moneypunct`) [edit]

### Member constants

Member | Definition
const bool `intl` (static) | `International`

### Member objects

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

[edit]

## 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

### [edit] Example

This example demonistrates how to apply monetary formatting rules of another language without changing the rest of the locale.

Run this code

    #include <iostream>
    #include <iomanip>
    #include <locale>
    int main()
    {
        long double mon = 1234567;
        std::locale::global(std::locale("en_US.utf8"));
        std::wcout.imbue(std::locale());
        std::wcout << L"american locale : " << std::showbase
                   << std::put_money(mon) << '\n';
        std::wcout.imbue(std::locale(std::wcout.getloc(),
                                     new std::moneypunct_byname<wchar_t>("ru_RU.utf8")));
        std::wcout << L"american locale with russian moneypunct: "
                   << std::put_money(mon) << '\n';
    }

Output:

    american locale : $12,345.67
    american locale with russian moneypunct: 12 345.67 руб

### [edit] See also

moneypunct | defines monetary formatting parameters used by std::money_get and std::money_put (class template) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/locale/moneypunct_byname&oldid=61628"