std::messages::do_open
Defined in header <locale> | ? | ? |
---|---|---|
public: catalog open( const std::basic_string<char>& name, const std::locale& loc ) const; | (1) | ? |
protected: virtual catalog do_open( const std::basic_string<char>& name, const std::locale& loc ) const; | (2) | ? |
1%29公共成员函数,调用受保护的虚拟成员函数do_open
最派生的类。
2%29得到一个类型的值catalog
28%遗传自std::messages_base
%29,可以传递给get()
从命名为name
此值在传递到close()
...
参数
name | - | name of the message catalog to open |
---|---|---|
loc | - | a locale object that provides additional facets that may be required to read messages from the catalog, such as std::codecvt to perform wide/multibyte conversions |
返回值
类型的非负值catalog
可以与get()
和close()
如果无法打开目录,则返回负值。
注记
在POSIX系统上,此函数调用通常转换为catopen()
.在GNU libstdc++中,它调用textdomain
...
实际的目录位置是实现定义的:用于目录。"sed"
%28安装在Unix实用程序中的消息目录'sed'
例如,在德语语言环境中,此函数调用打开的文件可能是/usr/lib/nls/msg/de_DE/sed.cat
,,,/usr/lib/locale/de_DE/LC_MESSAGES/sed.cat
,或/usr/share/locale/de/LC_MESSAGES/sed.mo
...
例
下面的示例演示了消息的检索:在一个典型的GNU/Linux系统上,它从/usr/share/locale/de/LC_MESSAGES/sed.mo
...
二次
#include <iostream>
#include <locale>
int main()
{
std::locale loc("de_DE.utf8");
std::cout.imbue(loc);
auto& facet = std::use_facet<std::messages<char>>(loc);
auto cat = facet.open("sed", loc);
if(cat < 0 )
std::cout << "Could not open german \"sed\" message catalog\n";
else
std::cout << "\"No match\" in German: "
<< facet.get(cat, 0, 0, "No match") << '\n'
<< "\"Memory exhausted\" in German: "
<< facet.get(cat, 0, 0, "Memory exhausted") << '\n';
facet.close(cat);
}
二次
产出:
二次
"No match" in German: Keine ?bereinstimmung
"Memory exhausted" in German: Speicher ersch?pft
二次
另见
二次
*。
? cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com