| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <locale> | ||
template< class CharT, | ||
Classstd::money_put encapsulates the rules for formatting monetary values as strings. The standard I/O manipulatorstd::put_money uses thestd::money_put facet of the I/O stream's locale.
Inheritance diagram
If astd::money_put specialization is not guaranteed to be provided by the standard library (see below), the behaviors of itsput() anddo_put() are not guaranteed as specified.
Contents |
The standard library is guaranteed to provide the following specializations (they arerequired to be implemented by any locale object):
Defined in header <locale> | |
| std::money_put<char> | creates narrow string representations of monetary values |
| std::money_put<wchar_t> | creates wide string representations of monetary values |
In addition, the standard library is also guaranteed to provide every specialization that satisfies the following type requirements:
CharT is one ofOutputIt must meet the requirements ofLegacyOutputIterator.| Type | Definition |
char_type | CharT |
string_type | std::basic_string<CharT> |
iter_type | OutputIt |
| Member | Description |
std::locale::idid[static] | the identifier of thefacet |
constructs a newmoney_put facet(public member function) | |
invokesdo_put(public member function) |
destructs amoney_put facet(protected member function) | |
[virtual] | formats a monetary value and writes to output stream (virtual protected member function)[edit] |
#include <iomanip>#include <iostream>#include <iterator>#include <locale> int main(){// using the I/O manipulatorstd::cout.imbue(std::locale("en_US.UTF-8"));std::cout<<"American locale: "<<std::showbase<<std::put_money(12345678.9)<<'\n'; // using the facet directlystd::cout.imbue(std::locale("de_DE.UTF-8"));std::cout<<"German locale: ";auto& f=std::use_facet<std::money_put<char>>(std::cout.getloc()); f.put({std::cout},false,std::cout,std::cout.fill(),12345678.9);std::cout<<'\n';}
Output:
American locale: $123,456.79German locale: 123.456,79 €
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 427 | C++98 | money_put was guaranteed to accept anyCharT thatmeets the requirements for a character on which any of the iostream components can be instantiated | only guarantees to acceptchar, wchar_t and other implementation- defined character types |
| LWG 2392 | C++98 | only character typeCharT could beguaranteed to be accepted by money_put | can guarantee to accept implementation- defined character container types |
| defines monetary formatting parameters used bystd::money_get andstd::money_put (class template)[edit] | |
| parses and constructs a monetary value from an input character sequence (class template)[edit] | |
(C++11) | formats and outputs a monetary value (function template)[edit] |