std::put_money
Defined in header <iomanip> | | |
---|---|---|
template< class MoneyT > /*unspecified*/ put_money( const MoneyT& mon, bool intl = false ); | | (since C++11) |
在表达式中使用时out << put_money(mon, intl)
,则转换货币价值。mon
指定的字符表示形式。std::money_put
当前注入的区域设置的方面。out
...
插入操作out << put_money(mon, intl)
表现为FormattedOutputFunction
...
参数
mon | - | a monetary value, either long double or std::basic_string |
---|---|---|
intl | - | use international currency strings if true, use currency symbols otherwise |
返回值
返回未指定类型的对象,以便在out
类型的输出流的名称。std::basic_ostream<CharT, Traits>
,然后表达out << put_money(mon, intl)
行为就像执行了以下代码:
typedefstd::ostreambuf_iterator<CharT, Traits> Iter;
typedefstd::money_put<CharT, Iter> MoneyPut;
const MoneyPut& mp =std::use_facet<MoneyPut>(out.getloc());
const Iter end = mp.put(Iter(out.rdbuf()), intl, out, out.fill(), mon);
if(end.failed())
out.setstate(std::ios::badbit);
例
二次
#include <iostream>
#include <iomanip>
int main()
{
long double mon = 123.45; // or std::string mon = "123.45";
std::cout.imbue(std::locale("en_US.utf8"));
std::cout << std::showbase
<< "en_US: " << std::put_money(mon)
<< " or " << std::put_money(mon, true) << '\n';
std::cout.imbue(std::locale("ru_RU.utf8"));
std::cout << "ru_RU: " << std::put_money(mon)
<< " or " << std::put_money(mon, true) << '\n';
std::cout.imbue(std::locale("ja_JP.utf8"));
std::cout << "ja_JP: " << std::put_money(mon)
<< " or " << std::put_money(mon, true) << '\n';
}
二次
产出:
二次
en_US: $1.23 or USD 1.23
ru_RU: 1.23 руб or 1.23 RUB
ja_JP: ¥123 or JPY 123
二次
另见
money_put | formats a monetary value for output as a character sequence (class template) |
---|---|
get_money (C++11) | parses a monetary value (function template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com