在线文档教程
C++
输入/输出 | Input/output

std::get_money

STD:得到[医]钱

Defined in header
template< class MoneyT > /*unspecified*/ get_money( MoneyT& mon, bool intl = false (since C++11)

在表达式中使用时in >> get_money(mon, intl),将字符输入解析为货币值,由std::money_get当前注入的区域设置的方面。in,并将值存储在mon...

提取操作in >> get_money(mon, intl)表现为FormattedInputFunction...

参数

mon-variable where monetary value will be written. Can be either long double or basic_string
intl-expects to find required international currency strings if true, expects optional currency symbols otherwise

返回值

返回未指定类型的对象,以便在in类型的输入流的名称。std::basic_istream<CharT, Traits>,然后表达in >> get_money(mon, intl)行为就像执行了以下代码:

typedefstd::istreambuf_iterator<CharT, Traits> Iter;

typedefstd::money_get<CharT, Iter> MoneyGet;

std::ios_base::iostateerr =std::ios_base::goodbit;

const MoneyGet &mg =std::use_facet<MoneyGet>(in.getloc()

mg.get(Iter(in.rdbuf()), Iter(), intl, in, err, mon

if(std::ios_base::goodbit!= err)

out.setstate(err

二次

#include <iostream> #include <sstream> #include <locale> #include <iomanip> int main() { std::istringstream in("$1,234.56 2.22 USD 3.33" long double v1, v2; std::string v3; in.imbue(std::locale("en_US.UTF-8") in >> std::get_money(v1) >> std::get_money(v2) >> std::get_money(v3, true if (in) { std::cout << std::quoted(in.str()) << " parsed as: " << v1 << ", " << v2 << ", " << v3 << '\n'; } else { std::cout << "Parse failed"; } }

二次

产出:

二次

"$1,234.56 2.22 USD 3.33" parsed as: 123456, 222, 333

二次

另见

money_getparses and constructs a monetary value from an input character sequence (class template)
put_money (C++11)formats and outputs a monetary value (function template)

© cppreference.com

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

http://en.cppreference.com/w/cpp/io/manip/get[医]钱