std::messages<CharT>:: get, std::messages<CharT>:: do_get
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
|
messages::get
messages::do_get
|
||||
|
定义于头文件
<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) | |
do_get
。
目录 |
参数
| cat | - | 从 open() 获取且尚未传递给 close() 的消息目录标识符 |
| set | - | 实现定义的参数,在 POSIX 中表示消息集 |
| msgid | - | 实现定义的参数,在 POSIX 中表示消息标识符 |
| dfault | - | 在目录中查找的字符串(若目录使用字符串查找),同时也是失败情况下返回的字符串 |
返回值
来自目录的消息,如果未找到则为 dfault 的副本。
注释
在POSIX系统上,此函数调用通常转换为对
catgets()
的调用,参数
set
、
msgid
和
dfault
会原样传递给
catgets()
。在GNU libstdc++中,此函数会忽略
set
和
msgid
,仅简单地在所需区域设置中调用GNU
gettext
(
dfault
)
。
示例
以下示例演示了消息检索功能:在典型的 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