std::messages_byname
Defined in header <locale> | | |
|---|---|---|
template< class CharT > class messages_byname : public std::messages<CharT>; | | |
std::messages_byname是std::messagesfacet,它封装了从构造时指定的区域设置的消息目录中检索字符串。
标准库提供了两个专门化。
在标头中定义<locale>
*。
STD:信息[医]名名<char>窄/多字节消息目录访问
STD:信息[医]名<wchar[医]T>宽字符串消息目录访问
成员类型
Member type | Definition |
|---|---|
catalog | std::messages_base<CharT>::catalog |
string_type | std::basic_string<CharT> |
成员函数
(constructor) | constructs a new messages_byname facet (public member function) |
|---|---|
(destructor) | destroys a messages_byname facet (protected member function) |
STD:信息[医]名称::消息[医]名名
explicit messages_byname( const char* name, std::size_t refs = 0 ); | | |
|---|---|---|
explicit messages_byname( const std::string& name, std::size_t refs = 0 ); | | (since C++11) |
构造一个新的std::messages_byname区域设置的方面name...
refs用于资源管理:如果refs == 0时,该实现破坏了面。std::locale保存它的对象被销毁。否则,该对象不会被销毁。
参数
name | - | the name of the locale |
|---|---|---|
refs | - | the number of references that link to the facet |
STD:信息[医]署名::~消息[医]名名
protected: ~messages_byname(); | | |
|---|
摧毁了这个面。
继承自STD:信息
成员类型
Member type | Definition |
|---|---|
char_type | charT |
string_type | std::basic_string<charT> |
成员对象
Member name | Type |
|---|---|
id (static) | std::locale::id |
成员函数
open | invokes do_open (public member function of std::messages) |
|---|---|
get | invokes do_get (public member function of std::messages) |
close | invokes do_close (public member function of std::messages) |
受保护成员函数
do_open virtual | opens a named message catalog (virtual protected member function of std::messages) |
|---|---|
do_get virtual | retrieves a message from an open message catalog (virtual protected member function of std::messages) |
do_close virtual | closes a message catalog (virtual protected member function of std::messages) |
例
二次
#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" メモリーが足りません二次
另见
messages | implements retrieval of strings from message catalogs (class template) |
|---|
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

