名稱空間
變體
操作

std::moneypunct_byname

來自 cppreference.com
< cpp‎ | locale
 
 
 
 
定義於標頭檔案 <locale>
template< class CharT, bool Intl = false >
class moneypunct_byname : public std::moneypunct<CharT, Intl>;

std::moneypunct_byname 是一個 std::moneypunct 面(facet),它封裝了在構造時指定區域設定(locale)的貨幣格式偏好。

目錄

[編輯] 特化

標準庫保證提供滿足以下型別要求的每種特化

  • CharTcharwchar_t 之一,並且
  • Intlbool 引數的一種可能特化。

[編輯] 巢狀型別

型別 定義
pattern std::money_base::pattern
string_type std::basic_string<CharT>

[編輯] 成員函式

(建構函式)
構造一個新的 moneypunct_byname
(公有成員函式) [編輯]
(解構函式)
銷燬一個 moneypunct_byname
(保護成員函式) [編輯]

std::moneypunct_byname::moneypunct_byname

explicit moneypunct_byname( const char* name, std::size_t refs = 0 );
explicit moneypunct_byname( const std::string& name, std::size_t refs = 0 );
(C++11 起)

為具有 name 的區域設定構造一個新的 std::moneypunct_byname 面。

refs 用於資源管理:如果 refs == 0,則當最後一個持有它的 std::locale 物件被銷燬時,實現會銷燬該面。否則,物件不會被銷燬。

引數

name - 區域設定的名稱
refs - 連結到 facet 的引用計數

std::moneypunct_byname::~moneypunct_byname

protected:
~moneypunct_byname();

銷燬 facet。

繼承自 std::moneypunct

巢狀型別

型別 定義
char_type CharT
string_type std::basic_string<CharT>

資料成員

成員 描述
std::locale::id id [static] facet 的識別符號
const bool intl [static] 國際

成員函式

呼叫 do_decimal_point
(std::moneypunct<CharT,International> 的公有成員函式) [編輯]
呼叫 do_thousands_sep
(std::moneypunct<CharT,International> 的公有成員函式) [編輯]
呼叫 do_grouping
(std::moneypunct<CharT,International> 的公有成員函式) [編輯]
呼叫 do_curr_symbol
(std::moneypunct<CharT,International> 的公有成員函式) [編輯]
呼叫 do_positive_signdo_negative_sign
(std::moneypunct<CharT,International> 的公有成員函式) [編輯]
呼叫 do_frac_digits
(std::moneypunct<CharT,International> 的公有成員函式) [編輯]
呼叫 do_pos_format/do_neg_format
(std::moneypunct<CharT,International> 的公有成員函式) [編輯]

受保護的成員函式

[虛擬函式]
提供用作小數點的字元
(std::moneypunct<CharT,International> 的虛保護成員函式) [編輯]
[虛擬函式]
提供用作千位分隔符的字元
(std::moneypunct<CharT,International> 的虛保護成員函式) [編輯]
[虛擬函式]
提供每對千位分隔符之間的數字個數
(std::moneypunct<CharT,International> 的虛保護成員函式) [編輯]
[虛擬函式]
提供用作貨幣識別符號的字串
(std::moneypunct<CharT,International> 的虛保護成員函式) [編輯]
提供指示正值或負值的字串
(std::moneypunct<CharT,International> 的虛保護成員函式) [編輯]
[虛擬函式]
提供小數點後顯示的位數
(std::moneypunct<CharT,International> 的虛保護成員函式) [編輯]
提供貨幣值的格式模式
(std::moneypunct<CharT,International> 的虛保護成員函式) [編輯]

繼承自 std::money_base

巢狀型別

型別 定義
enum part { none, space, symbol, sign, value }; 非限定列舉型別
struct pattern { char field[4]; }; 貨幣格式型別
列舉常量 描述
允許但不強制要求空格,除了在最後一個位置,該位置不允許有空格
space 需要一個或多個空格字元
symbol 要求 std::moneypunct::curr_symbol 返回的字元序列
sign 要求 std::moneypunct::positive_signstd::moneypunct::negative_sign 返回的第一個字元
value 需要絕對的數字貨幣值

[編輯] 示例

本例演示如何在不改變區域設定其餘部分的情況下應用另一種語言的貨幣格式規則。

#include <iomanip>
#include <iostream>
#include <locale>
 
int main()
{
    long double mon = 1234567;
    std::locale::global(std::locale("en_US.utf8"));
    std::wcout.imbue(std::locale());
    std::wcout << L"american locale: " << std::showbase
               << std::put_money(mon) << '\n';
    std::wcout.imbue(std::locale(std::wcout.getloc(),
                                 new std::moneypunct_byname<wchar_t>("ru_RU.utf8")));
    std::wcout << L"american locale with russian moneypunct: "
               << std::put_money(mon) << '\n';
}

輸出

american locale: $12,345.67
american locale with russian moneypunct: 12 345.67 руб

[編輯] 參閱

定義由 std::money_getstd::money_put 使用的貨幣格式引數
(類模板) [編輯]