std::get_money
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <iomanip> 中定义
|
||
template< class MoneyT > /*unspecified*/ get_money( MoneyT& mon, bool intl = false ); |
(C++11 起) | |
When used in an expression in >> get_money(mon, intl), parses the character input as a monetary value, as specified by the std::money_get facet of the locale currently imbued in in
, and stores the value in mon
.
This function behaves as a formatted input function.
目录 |
[编辑] 参数
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)的行为,如果下面的代码被执行对象的类型不明确原文:
Returns an object of unspecified type such that if
in
is the name of an output stream of type std::basic_istream<CharT, Traits>, then the expression in >> get_money(mon, intl) behaves as if the following code was executed:typedef std::istreambuf_iterator<CharT, Traits> Iter;
typedef std::money_get<CharT, Iter> MoneyGet;
std::ios_base::iostate err = 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); std::cout << '"' << in.str() << "\" parsed as: " << v1 << ", " << v2 << ", " << v3 << '\n'; }
输出:
"$1,234.56 2.22 USD 3.33" parsed as: 123456, 222, 333
[编辑] 另请参阅
解析和构造的货币价值,从一个输入字符序列 原文: parses and constructs a monetary value from an input character sequence (类模板) | |
(C++11) |
格式和输出的货币价值 原文: formats and outputs a monetary value (函数模板) |