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

std::messages::get

Defined in header <locale>

public: string_type get( catalog cat, int set, int msgid, const string_type& dfault ) const;

(1)

protected: virtual string_type do_get( catalog cat, int set, int msgid, const string_type& dfault ) const;

(2)

1%29公共成员函数,调用受保护的虚拟成员函数do_get最派生的类。

2%29从打开的邮件目录中获得一条消息。cat使用值set,,,msgiddfault在执行---确定的方式下。如果在目录中找不到预期的消息,则返回dfault...

参数

cat

-

identifier of message catalog obtained from open() and not yet passed to close()

set

-

implementation-defined argument, message set in POSIX

msgid

-

implementation-defined argument, message id in POSIX

dfault

-

the string to look up in the catalog (if the catalog uses string look-up) and also the string to return in case of a failure

返回值

目录中的消息或dfault如果没有发现。

注记

在POSIX系统上,此函数调用通常转换为catgets(),以及参数set,,,msgid,和dfault传递给catgets()就像现在一样。在GNU libstdc++中,此函数忽略setmsgid只需调用GNUgettext(dfault)在所需的地区。

下面的示例演示了消息的检索:在一个典型的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。

扫码关注腾讯云开发者

领取腾讯云代金券