首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::messages::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得到一个类型的值catalog28%遗传自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...

二次

代码语言:javascript
复制
#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);
}

二次

产出:

二次

代码语言:javascript
复制
"No match" in German: Keine ?bereinstimmung
"Memory exhausted" in German: Speicher ersch?pft

二次

另见

二次

*。

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com