public member function
iter_type put (iter_type s, bool intl, ios_base& str, char_type fill, long double units) const;
iter_type put (iter_type s, bool intl, ios_base& str, char_type fill, const string_type& digits) const;
Format monetary expression
Formats either units or digits as a sequence of characters expressing a monetary amount.
The function writes the characters resulting from the formatting operation into the sequence whose first character is pointed by s.
An iterator to the character right after the last element written to the output sequence is returned by the function.
Internally, this function simply calls the virtual protected member do_put, which uses the locale selected in str to obtain format details (through facet
moneypunct<char_type,intl>) and to widen characters (using ctype::widen).
This default implementation of do_put is affected by the following format flags of str:
|format flag||flag value||effect|
|showbase||showbase (set)||The currency sign is included in the representation|
|noshowbase (not set)||The currency sign is not included in the representation|
|adjustfield||internal||Any fill characters appear where |
space appears in the formatting pattern (see moneypunct::pos_format).
|left||Any fill characters are placed after the other characters.|
|right, or not set||Any fill characters are placed before the other characters.|
- Iterator pointing to the first character of the output sequence.
The sequence shall be large enough to accommodate for the whole expression.
Member type iter_type is the facet's iterator type (defined as an alias of time_put's second template parameter, OutputIterator). By default, this is an ostreambuf_iterator, allowing implicit conversions from basic_ostream objects.
true for international representation,
This is used to select the proper instatiation of moneypunct.
- Object of a class derived from ios_base (generally an output stream object). It is only used to obtain formatting information (nothing is written to this stream by this function).
- Fill character. The fill character is used in output insertion operations to fill spaces when the format requires some character padding.
Member type char_type is the facet's character type (defined as an alias of time_put's first template parameter, charT).
- Value to be formatted by the function.
- A string with the digits conforming the monetary value to be written.
Member type string_type is an instantiation of basic_string with the same character type as the facet (defined as an alias of
charT is money_get's first template parameter).
The next character in the sequence right after the last one written.
Member type iter_type is the facet's iterator type (defined as an alias of money_put's second template parameter, OutputIterator).
// money_put example
#include <iostream> // std::cin, std::cout
#include <locale> // std::locale, std::money_put, std::use_facet
int main ()
const std::money_put<char>& monput = std::use_facet<std::money_put<char> >(std::cout.getloc());
monput.put (std::cout, false, std::cout, ' ', 12.95);
std::cout << '\n';
monput.put (std::cout, false, std::cout, ' ', "1295");
std::cout << '\n';
The facet object is accessed.
The sequence pointed by s is modified.
If an exception is thrown, there are no changes in the facet object, although the destination array may have been modified.