public member function
<locale>

std::money_put::put

numerical (1)
iter_type put (iter_type s, bool intl, ios_base& str,               char_type fill, long double units) const;
string (2)
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.

函数返回一个指向输出序列中最后一个写入元素之后一个位置的迭代器。

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标志值effect
showbaseshowbase (set)The currency sign is included in the representation
noshowbase (not set)The currency sign is not included in the representation
adjustfieldinternalAny fill characters appear where none or space appears in the formatting pattern (see moneypunct::pos_format).
leftAny fill characters are placed after the other characters.
right, or not setAny fill characters are placed before the other characters.

参数

s
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.
intl
true for international representation, false otherwise.
This is used to select the proper instatiation of moneypunct.
str
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
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).
units
Value to be formatted by the function.
digits
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 basic_string<charT>, where charT is money_get's first template parameter).

返回值

最后写入字符之后的序列中的下一个字符。
Member type iter_type is the facet's iterator type (defined as an alias of money_put's second template parameter, OutputIterator).

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 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';

  return 0;
}

可能的输出

13
1295


数据竞争

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.

另见