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

std::money_put

Defined in header <locale>

?

?

template< class CharT, class OutputIt = std::ostreambuf_iterator<CharT> > class money_put;

?

?

std::money_put封装将货币值格式化为字符串的规则。标准I/O机械手std::put_money使用std::money_putI/O流%27s区域设置的方面。

二次

二次

继承图

类型要求

-输入必须符合输入器的要求。

*。

专门性

标准库提供了两个独立的%28区域独立的%29完全专门化和两个部分专门化:

在标头中定义<locale>

*。

STD:钱[医]放<char>创建货币值的窄字符串表示。

STD:钱[医][医]T>创建货币价值的宽字符串表示。

STD:钱[医]PUT<char,OutputIt>使用自定义输出迭代器创建货币值的窄字符串表示

STD:钱[医]放置<wchar[医]T,OutputIt>使用自定义输出迭代器创建货币值的宽字符串表示

此外,在C++程序中构造的每个locale对象都实现了自己的%28 locale特定于这些专门化的%29版本。

成员类型

Member type

Definition

char_type

CharT

string_type

std::basic_string<CharT>

iter_type

OutputIt

成员函数

(constructor)

constructs a new money_put facet (public member function)

(destructor)

destructs a money_put facet (protected member function)

put

invokes do_put (public member function)

受保护成员函数

do_put virtual

formats a monetary value and writes to output stream (virtual protected member function)

成员对象

static std::locale::id id

id of the locale (public member object)

二次

代码语言:javascript
复制
#include <iostream>
#include <locale>
#include <iomanip>
#include <iterator>
int main()
{
    // using the IO manipulator
    std::cout.imbue(std::locale("en_US.UTF-8"));
    std::cout << "american locale: "
               << std::showbase << std::put_money(12345678.9)<< '\n';
 
    // using the facet directly
    std::cout.imbue(std::locale("de_DE"));
    std::cout << "german locale: " ;
    std::ostreambuf_iterator<char> out(std::cout);
    auto& f = std::use_facet<std::money_put<char>>(std::cout.getloc());
    f.put(out, false, std::cout, std::cout.fill(), 12345678.9 );
    std::cout << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
american locale: $123,456.79
german locale: 123.456,79 EUR

二次

另见

moneypunct

defines monetary formatting parameters used by std::money_get and std::money_put (class template)

money_get

parses and constructs a monetary value from an input character sequence (class template)

put_money (C++11)

formats and outputs a monetary value (function template)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com