名稱空間
變體
操作

std::messages_byname

來自 cppreference.com
< cpp‎ | locale
 
 
 
 
定義於標頭檔案 <locale>
template< class CharT >
class messages_byname : public std::messages<CharT>;

std::messages_byname 是一個 std::messages facet,它封裝了從構建時指定的區域設定的訊息目錄中檢索字串的功能。

目錄

[編輯] 特化

標準庫保證提供以下特化

定義於標頭檔案 <locale>
std::messages_byname<char> 窄字元/多位元組訊息目錄訪問
std::messages_byname<wchar_t> 寬字串訊息目錄訪問

[編輯] 巢狀型別

型別 定義
catalog std::messages_base<CharT>::catalog
string_type std::basic_string<CharT>

[編輯] 成員函式

(建構函式)
構造新的 messages_byname facet
(public member function) [編輯]
(解構函式)
銷燬 messages_byname facet
(protected member function) [編輯]

std::messages_byname::messages_byname

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

為名稱為 name 的區域設定構造一個新的 std::messages_byname facet。

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

引數

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

std::messages_byname::~messages_byname

protected:
~messages_byname();

銷燬 facet。

繼承自 std::messages

巢狀型別

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

[編輯] 資料成員

成員 描述
std::locale::id id [static] facet 的識別符號

成員函式

呼叫 do_open
(std::messages<CharT> 的公共成員函式) [編輯]
呼叫 do_get
(std::messages<CharT> 的公共成員函式) [編輯]
呼叫 do_close
(std::messages<CharT> 的公共成員函式) [編輯]

受保護的成員函式

[virtual]
開啟一個命名訊息目錄
(std::messages<CharT> 的虛保護成員函式) [編輯]
[virtual]
從已開啟的訊息目錄中檢索訊息
(std::messages<CharT> 的虛保護成員函式) [編輯]
[virtual]
關閉訊息目錄
(std::messages<CharT> 的虛保護成員函式) [編輯]

繼承自 std::messages_base

巢狀型別

型別 定義
catalog 未指定有符號整數型別

[編輯] 示例

#include <iostream>
#include <locale>
 
void try_with(const std::locale& loc)
{
    const std::messages<char>& facet = std::use_facet<std::messages<char>>(loc);
 
    std::messages<char>::catalog cat = facet.open("sed", std::cout.getloc());
    if (cat < 0)
        std::cout << "Could not open \"sed\" message catalog\n";
    else
        std::cout << "\"No match\" "
                  << facet.get(cat, 0, 0, "No match") << '\n'
                  << "\"Memory exhausted\" " 
                  << facet.get(cat, 0, 0, "Memory exhausted") << '\n';
 
    facet.close(cat);
}
 
int main()
{
    std::locale loc("en_US.utf8");
    std::cout.imbue(loc);
 
    try_with(std::locale(loc, new std::messages_byname<char>("de_DE.utf8")));
    try_with(std::locale(loc, new std::messages_byname<char>("fr_FR.utf8")));
    try_with(std::locale(loc, new std::messages_byname<char>("ja_JP.utf8")));
}

可能的輸出

"No match" Keine Übereinstimmung
"Memory exhausted" Speicher erschöpft
"No match" Pas de concordance
"Memory exhausted" Mémoire épuisée
"No match" 照合しません
"Memory exhausted" メモリーが足りません

[編輯] 參閱

實現從訊息目錄檢索字串
(類模板) [編輯]