Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
何时以及如何使用std::locale::messages? < C++标准定义了六个方面: CORATE < /COD>, cType < /代码>,货币< /代码>,数字< /代码>,时间< />代码>和消息< /C> >_C++_C++11_Internationalization_Locale_Facet - Fatal编程技术网

何时以及如何使用std::locale::messages? < C++标准定义了六个方面: CORATE < /COD>, cType < /代码>,货币< /代码>,数字< /代码>,时间< />代码>和消息< /C> >

何时以及如何使用std::locale::messages? < C++标准定义了六个方面: CORATE < /COD>, cType < /代码>,货币< /代码>,数字< /代码>,时间< />代码>和消息< /C> >,c++,c++11,internationalization,locale,facet,C++,C++11,Internationalization,Locale,Facet,我知道前五个的用法,但我不知道何时以及如何使用最后一个:std::locale::messages 任何示例?用于打开包含翻译字符串的消息目录(最常见的GNU)。下面是一个示例,它使用Linux上的德语(forsed)打开现有邮件目录,检索(使用get())并输出英文字符串的翻译: #include <iostream> #include <locale> int main() { std::locale loc("de_DE.utf8"); std::

我知道前五个的用法,但我不知道何时以及如何使用最后一个:
std::locale::messages

任何示例?

用于打开包含翻译字符串的消息目录(最常见的GNU)。下面是一个示例,它使用Linux上的德语(for
sed
)打开现有邮件目录,检索(使用
get()
)并输出英文字符串的翻译:

#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);
}

编辑:根据。

进行澄清,而不仅仅是GNU gettext。消息目录是POSIX的一部分(例如gencat(1)、catopen(3))。Windows也有消息目录,尽管我不确定他们是否曾费心实现标准的语言环境消息方面。
"No match" in German: Keine Übereinstimmung
"Memory exhausted" in German: Speicher erschöpft