Namespaces
Variants

std:: messages_byname

From cppreference.net
定义于头文件 <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 >

成员函数

(constructor)
构造新的 messages_byname facet
(公开成员函数)
(destructor)
销毁 messages_byname facet
(受保护成员函数)

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 ,当最后一个持有该 facet 的 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 [静态] facet 的标识符

成员函数

调用 do_open
( std::messages<CharT> 的公开成员函数)
调用 do_get
( std::messages<CharT> 的公开成员函数)
调用 do_close
( std::messages<CharT> 的公开成员函数)

受保护成员函数

[虚函数]
打开命名消息目录
( std::messages<CharT> 的虚受保护成员函数)
[虚函数]
从已打开的消息目录中检索消息
( std::messages<CharT> 的虚受保护成员函数)
[虚函数]
关闭消息目录
( 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" メモリーが足りません

参见

实现从消息目录中检索字符串
(类模板)