std::put_money

来自cppreference.com
< cpp‎ | io‎ | manip
 
 
 
输入/输出操纵符
浮点格式化
整数格式化
布尔格式化
域宽与填充控制
其他格式化
空白符处理
输出冲入
状态标志操纵
时间与金钱 I/O
(C++11)
(C++11)
put_money
(C++11)
(C++11)
带引号操纵符
(C++14)
 
在标头 <iomanip> 定义
template<class MoneyT >
/*未指定*/ put_money(const MoneyT& mon, bool intl =false);
(C++11 起)

用于表达式 out << put_money(mon, intl) 时,转换货币值 monout 中当前浸染的本地环境的 std::money_put 刻面所指定的字符表示。

out << put_money(mon, intl) 中的插入操作表现为有格式输出函数(FormattedOutputFunction)

目录

[编辑]参数

mon - 货币值,longdoublestd::basic_string 之一
intl - true 的情况下使用国际通货字符串,否则使用通货符号

[编辑]返回值

一个满足以下条件但未指定类型的对象:

其中函数 f 定义如下:

template<class CharT, class Traits, class MoneyT>void f(std::basic_ios<CharT, Traits>& str, const MoneyT& mon, bool intl){using Iter =std::ostreambuf_iterator<CharT, Traits>;using MoneyPut =std::money_put<CharT, Iter>;   const MoneyPut& mp =std::use_facet<MoneyPut>(str.getloc());const Iter end = mp.put(Iter(str.rdbuf()), intl, str, str.fill(), mon);   if(end.failed()) str.setstate(std::ios_base::badbit);}

[编辑]示例

#include <iomanip>#include <iostream>   int main(){longdouble mon =123.45;// 或 std::string mon = "123.45";   std::cout.imbue(std::locale("en_US.UTF-8"));std::cout<<std::showbase<<"en_US: "<< std::put_money(mon)<<" or "<< std::put_money(mon, true)<<'\n';   std::cout.imbue(std::locale("ru_RU.UTF-8"));std::cout<<"ru_RU: "<< std::put_money(mon)<<" or "<< std::put_money(mon, true)<<'\n';   std::cout.imbue(std::locale("ja_JP.UTF-8"));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

[编辑]参阅

格式化货币值为字符序列以输出
(类模板)[编辑]
(C++11)
剖析货币值
(函数模板)[编辑]
close