std::messages_byname
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   定义于头文件  <locale>
  | 
||
|   template< class CharT > class messages_byname : public std::messages<CharT>;  | 
||
std::messages_byname 是 std::messages 平面,它封装从在其构造时指定的 locale 的消息目录取得字符串。
标准库提供二个特化
|   定义于头文件  
<locale>  | |
| std::messages_byname<char> | 窄/多字节字符串消息目录访问 | 
| std::messages_byname<wchar_t> | 宽字符串消息目录访问 | 
成员类型
| 成员类型 | 定义 | 
  catalog
 | 
  std::messages_base<CharT>::catalog
 | 
  string_type
 | 
  std::basic_string<CharT>
 | 
成员函数
|     (构造函数)  | 
  构造新的 messages_byname 平面 (公开成员函数)  | 
|     (析构函数)  | 
  析构 messages_byname 平面 (受保护成员函数)  | 
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 平面。 
refs 用于资源管理:在销毁最后一个保有平面的 std::locale 对象时,若 refs == 0 ,则实现销毁平面对象。否则,不销毁对象。
参数
| name | - | 本地环境的名称 | 
| refs | - | 链接到该平面的引用数 | 
std::messages_byname::~messages_byname
|   protected: ~messages_byname();  | 
||
销毁平面。
继承自 std::messages
成员类型
| 成员类型 | 定义 | 
  char_type
 | 
  charT
 | 
  string_type
 | 
  std::basic_string<charT>
 | 
成员对象
| 成员名 | 类型 | 
  id [静态]
 | 
std::locale::id | 
成员函数
  调用 do_open  ( std::messages<CharT> 的公开成员函数)  | |
  调用 do_get  ( std::messages<CharT> 的公开成员函数)  | |
  调用 do_close  ( std::messages<CharT> 的公开成员函数)  | 
受保护成员函数
|    [虚]  | 
  打开具名消息目录  ( std::messages<CharT> 的虚受保护成员函数)  | 
|    [虚]  | 
  从打开的消息目录获取消息  ( std::messages<CharT> 的虚受保护成员函数)  | 
|    [虚]  | 
  关闭消息目录  ( std::messages<CharT> 的虚受保护成员函数)  | 
示例
运行此代码
#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" メモリーが足りません
参阅
|   实现从消息目录获取字符串  (类模板)  |