From cppreference.com
template<classCharT>classmessages_byname:publicstd::messages<CharT>;std::messages_byname is a
facet which encapsulates retrieval of strings from message catalogs of the locale specified at its construction.
Specializations
The standard library is guaranteed to provide the following specializations:
std::messages_byname<char>narrow/multibyte message catalog access std::messages_byname<wchar_t>wide string message catalog access Nested types
Type Definition catalogstd::messages_base<CharT>::catalogstring_typestd::basic_string<CharT>Member functions
std::messages_byname::messages_byname
explicitmessages_byname(constchar*name,std::size_trefs=0);explicitmessages_byname(conststd::string&name,std::size_trefs=0);(since C++11)Constructs a new std::messages_byname facet for a locale with name.
refs is used for resource management: if refs==0, the implementation destroys the facet, when the last
object holding it is destroyed. Otherwise, the object is not destroyed.
Parameters
name - the name of the locale refs - the number of references that link to the facet std::messages_byname::~messages_byname
protected:~messages_byname();Destroys the facet.
Inherited from
Nested types
Type Definition char_typeCharTstring_typestd::basic_string<CharT>Data members
Member functions
invokes do_open
(public member function of std::messages<CharT>)
invokes do_get
(public member function of std::messages<CharT>)
invokes do_close
(public member function of std::messages<CharT>)
Protected member functions
[virtual]
opens a named message catalog
(virtual protected member function of std::messages<CharT>)
[virtual]
retrieves a message from an open message catalog
(virtual protected member function of std::messages<CharT>)
[virtual]
closes a message catalog
(virtual protected member function of std::messages<CharT>)
Inherited from
Nested types
Type Definition catalogan unspecified signed integer type Example
Run this code
#include<iostream>#include<locale>voidtry_with(conststd::locale&loc){conststd::messages<char>&facet=std::use_facet<std::messages<char>>(loc);std::messages<char>::catalogcat=facet.open("sed",std::cout.getloc());if(cat<0)std::cout<<"Could not open \"sed\" message catalog\n";elsestd::cout<<"\"No match\" "<<facet.get(cat,0,0,"No match")<<'\n'<<"\"Memory exhausted\" "<<facet.get(cat,0,0,"Memory exhausted")<<'\n';facet.close(cat);}intmain(){std::localeloc("en_US.utf8");std::cout.imbue(loc);try_with(std::locale(loc,newstd::messages_byname<char>("de_DE.utf8")));try_with(std::locale(loc,newstd::messages_byname<char>("fr_FR.utf8")));try_with(std::locale(loc,newstd::messages_byname<char>("ja_JP.utf8")));}Possible output:
"No match" Keine Übereinstimmung "Memory exhausted" Speicher erschöpft "No match" Pas de concordance "Memory exhausted" Mémoire épuisée "No match" 照合しません "Memory exhausted" メモリーが足りません See also
implements retrieval of strings from message catalogs
(class template)