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

std::money_get

Defined in header <locale>

?

?

template< class CharT, class InputIt = std::istreambuf_iterator<CharT> > class money_get;

?

?

类模板std::money_get封装用于从字符流解析货币值的规则。标准I/O机械手std::get_money使用std::money_getI/O流%27s区域设置的方面。

二次

二次

继承图

类型要求

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

*。

专门性

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

在标头中定义<locale>

*。

STD:钱[医]弄到<char>解析货币价值的狭义字符串表示

STD:钱[医]得到<wchar[医]T>解析货币价值的宽字符串表示。

STD:钱[医]使用自定义输入迭代器获取<char,InputIt>解析货币值的窄字符串表示

STD:钱[医]得到<wchar[医]使用自定义输入迭代器解析货币值的宽字符串表示

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

成员类型

Member type

Definition

char_type

CharT

string_type

std::basic_string<CharT>

iter_type

InputIt

成员函数

(constructor)

constructs a new money_get facet (public member function)

(destructor)

destructs a money_get facet (protected member function)

get

invokes do_get (public member function)

受保护成员函数

do_get virtual

parses a monetary value from an input stream (virtual protected member function)

成员对象

static std::locale::id id

id of the locale (public member object)

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
#include <locale>
#include <iomanip>
#include <iterator>
int main()
{
    std::string str = "$1.11 $2.22 $3.33";
    std::cout << std::fixed << std::setprecision(2);
 
    std::cout << '"' << str << "\" parsed with the I/O manipulator: ";
    std::istringstream s1(str);
    s1.imbue(std::locale("en_US.UTF-8"));
    long double val;
    while(s1 >> std::get_money(val))
        std::cout << val/100 << ' ';
    std::cout << '\n';
 
    str = "USD  1,234.56";
    std::cout << '"' << str << "\" parsed with the facet directly: ";
    std::istringstream s2(str);
    s2.imbue(std::locale("en_US.UTF-8"));
    auto& f = std::use_facet<std::money_get<char>>(s2.getloc());
    std::ios_base::iostate err;
    std::istreambuf_iterator<char> beg(s2), end;
    f.get(beg, end, true, s2, err, val);
    std::cout << val/100 << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
"$1.11 $2.22 $3.33" parsed with the I/O manipulator: 1.11 2.22 3.33
"USD  1,234.56" parsed with the facet directly: 1234.56

二次

另见

moneypunct

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

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