std::moneypunct_byname
From cppreference.com
Template:ddcl list begin <tr class="t-dsc-header">
<td>Defined in header
</td>
<locale>
<td></td> <td></td> </tr> <tr class="t-dcl ">
<td class="t-dcl-nopad">template< class CharT, bool Intl = false >
class moneypunct_byname : public std::moneypunct<CharT, Intl>;
</td>
class moneypunct_byname : public std::moneypunct<CharT, Intl>;
<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end
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 |
Contents |
Member types
Member type | Definition |
pattern
|
std::money_base::pattern |
string_type
|
std::basic_string<CharT> |
Member functions
constructs a new moneypunct_byname facet (public member function) | |
destructs a moneypunct_byname facet (protected member function) |
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 руб