Namespaces
Variants

std::messages<CharT>:: close, std::messages<CharT>:: do_close

From cppreference.net
定义于头文件 <locale>
public :
void close ( catalog c ) const ;
(1)
protected :
virtual void do_close ( catalog c ) const ;
(2)
1) 公开成员函数,调用最派生类的受保护虚成员函数 do_close
2) 释放与打开的目录相关联的实现定义资源,该目录由类型为 catalog (继承自 std::messages_base )的值 c 指定,该值是从 open() 获取的。

目录

参数

c - 一个有效的已打开目录标识符,尚未对其调用 close()

返回值

(无)

注释

在POSIX系统上,此函数调用通常转换为对 catclose() 的调用。在基于GNU gettext() 实现的GNU libstdc++中,该函数不执行任何操作。

示例

以下示例演示了消息检索功能:在典型的 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

另请参阅