Namespaces
Variants
Views
Actions

std::messages

From cppreference.com
Defined in header <locale>
template< class charT >
class messages : public std::locale::facet, public std::messages_base;

Class template std::messages encapsulates retrieval of strings from message catalogs, such as the ones provided by GNU gettext or by POSIX catgets.

Two specializations are provided by the standard library and are implemented by all locale objects created in a C++ program:

Defined in header <locale>
std::messages<char> accesses narrow string message catalog
std::messages<wchar_t> accesses wide string message catalog

Contents

[edit] Member types

Member type Definition
char_type charT
string_type std::basic_string<charT>

[edit] Member objects

Member name Type
id (static) std::locale::id

[edit] Member functions

constructs a new messages facet
(public member function)
destructs a messages facet
(protected member function)
invokes do_open
(public member function)
invokes do_get
(public member function)
invokes do_close
(public member function)

[edit] Protected member functions

[virtual]
opens a named message catalog
(virtual protected member function)
[virtual]
retrieves a message from an open message catalog
(virtual protected member function)
[virtual]
closes a message catalog
(virtual protected member function)

Inherited from std::messages_base

Type Definition
catalog int


[edit] Example

The following example demonstrated retrieval of messages: on a typical GNU/Linux system it reads from /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);
}

Output:

"No match" in German: Keine Übereinstimmung
"Memory exhausted" in German: Speicher erschöpft

[edit] See also

defines messages catalog type
(class template)
creates a messages facet for the named locale
(class template)