std::moneypunct<CharT,International>::positive_sign, do_positive_sign, negative_sign, do_negative_sign
來自 cppreference.com
< cpp | 本地化 (locale) | moneypunct
定義於標頭檔案 <locale> |
||
public: string_type positive_sign() const; |
(1) | |
public: string_type negative_sign() const; |
(2) | |
protected: virtual string_type do_positive_sign() const; |
(3) | |
protected: virtual string_type do_negative_sign() const; |
(4) | |
1) 公有成員函式,呼叫最派生類的成員函式
do_positive_sign
。2) 公有成員函式,呼叫最派生類的成員函式
do_negative_sign
。3) 返回用於格式化正貨幣值的字串。
3) 返回用於格式化負貨幣值的字串。
返回字串的第一個字元是出現在 pos_format()/neg_format() 中由值 sign 指示的位置的字元。其餘字元出現在貨幣字串的其餘部分*之後*。
特別地,對於 "-" 的 negative_sign,格式化可能顯示為 "-1.23 €",而對於 "()" 的 negative_sign,則顯示為 "(1.23 €)"。
[編輯] 返回值
型別為 string_type
的字串,其中包含用作正號或負號的字元。
[編輯] 示例
執行此程式碼
#include <iomanip> #include <iostream> #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("de_DE.utf8"); std::cout.imbue(loc); std::cout << loc.name() << " negative sign is '" << std::use_facet<std::moneypunct<char>>(loc).negative_sign() << "' for example: " << std::showbase << std::put_money(-1234) << '\n'; std::locale loc2("ms_MY.utf8"); std::cout.imbue(loc2); std::cout << loc2.name() << " negative sign is '" << std::use_facet<std::moneypunct<char>>(loc2).negative_sign() << "' for example: " << std::put_money(-1234) << '\n'; std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("de_DE.utf8"))); std::cout << "de_DE.utf8 with negative_sign set to \"()\": " << std::put_money(-1234) << '\n'; }
輸出
de_DE.utf8 negative sign is '-' for example: -12,34 € ms_MY.utf8 negative sign is '()' for example: (RM12.34) de_DE.utf8 with negative_sign set to "()": (12,34 €)
[編輯] 參閱
[virtual] |
提供貨幣值的格式模式 (虛保護成員函式) |