首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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);

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com