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

std::money_put::put

Defined in header <locale>

public: iter_type put(iter_type out, bool intl, std::ios_base& f, char_type fill, long double quant) const;

(1)

iter_type put(iter_type out, bool intl, std::ios_base& f, char_type fill, const string_type& quant) const;

(2)

protected: virtual iter_type do_put(iter_type out, bool intl, std::ios_base& str, char_type fill, long double units) const;

(3)

virtual iter_type do_put(iter_type out, bool intl, std::ios_base& str, char_type fill, const string_type& digits) const;

(4)

格式化货币值并将结果写入输出流。

1-2%29个公共成员函数,调用成员函数do_put最派生的类。

3%29数值参数units转换为宽字符串,就像ct.widen(buf1, buf1 +std::sprintf(buf1, "%.0Lf", units), buf2),在哪里ctstd::ctype小面str.getloc()buf1buf2足够大的字符缓冲区。生成的字符串。buf2被处理、格式化和输出到out就像下面所描述的那样。

字符串参数的4%29digits,则只有通过比较以下方法确定的可选前导减号%28 ASct.widen('-'),在哪里ctstd::ctype小面str.getloc()%29和以下数字字符%28被ct%29作为要处理、格式化和输出到out如下所述。

给定前面步骤中的字符序列,如果第一个字符等于ct.widen('-'),电话mp.neg_format()若要获得格式设置,请执行以下操作pattern,否则调用mp.pos_format(),在哪里mpstd::moneypunct<CharT, intl>小面str.getloc()...

按要求插入数千个分隔符和小数点字符。mp.grouping(),,,mp.frac_digits(),,,mp.decimal_point(),和mp.thousands_sep(),并将结果字符串放置在输出序列中,其中value出现在格式设置模式中。

如果str.flags() & str.showbase是非零%28std::showbase操作程序使用%29,然后通过调用mp.curr_symbol()并将其置于输出序列中,其中symbol出现在格式设置模式中。

如果mp.positive_sign()%28在使用%29或mp.negative_sign()%28如果使用负格式模式,%29返回一个字符串,其中包含多个字符,返回的第一个字符放在输出序列中sign出现在格式化模式中,其余字符放在所有其他字符之后,例如格式化模式。{sign, value, space, symbol有单位123和消极[医]标志"-"可能导致"-1.23 €",而不是[医]标志"()"会产生"(1.23 €)"...

如果为指定格式生成的字符数小于str.width()的副本fill插入以使输出序列的总长度精确地达到。str.width(),如下:

  • 如果str.flags() & str.adjustfield等号str.internal,则插入填充字符的位置。nonespace出现在格式设置模式中。
  • 否则,如果str.flags() & str.adjustfield等号str.left的副本fill在所有其他字符之后追加。
  • 否则,填充字符放在所有其他字符之前。

最后,打电话str.width(0)取消任何std::setw...

返回值

在产生的最后一个字符之后立即指向的迭代器。

注记

这些货币单位被认为是这种货币最小的非小数单位:在美国是美分,在日本是日元。

二次

代码语言:javascript
复制
#include <iostream>
#include <iomanip>
#include <locale>
 
struct my_punct : std::moneypunct_byname<char, false> {
    my_punct(const char* name) : moneypunct_byname(name) {}
    string_type do_negative_sign() const { return "()"; }
};
 
int main()
{
    std::locale loc("ru_RU.utf8");
    std::cout.imbue(loc);
    long double units = -123.45;
    std::cout << "In Russian locale, " << units << " prints as "
              << std::showbase;
// note, the following is equivalent to simply std::put_money(units)
    std::use_facet<std::money_put<char>>(loc).put(
             std::ostreambuf_iterator<char>(std::cout),
             false, std::cout, std::cout.fill(), units);
    std::cout << '\n';
 
    std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("ru_RU.utf8")));
    std::cout << "With negative_sign set to \"()\", it prints  as ";
    std::use_facet<std::money_put<char>>(loc).put(
             std::ostreambuf_iterator<char>(std::cout),
             false, std::cout, std::cout.fill(), units);
    std::cout << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
In Russian locale, -123,45 prints as -1.23 руб
With negative_sign set to "()", it prints  as (1.23 руб)

二次

另见

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。

扫码关注腾讯云开发者

领取腾讯云代金券