Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::messages_byname

      From cppreference.com
      <cpp‎ |locale
       
       
       
      Localization library
       
      Defined in header<locale>
      template<class CharT>
      class messages_byname:publicstd::messages<CharT>;

      std::messages_byname is astd::messages facet which encapsulates retrieval of strings from message catalogs of the locale specified at its construction.

      Contents

      [edit]Specializations

      The standard library is guaranteed to provide the following specializations:

      Defined in header<locale>
      std::messages_byname<char> narrow/multibyte message catalog access
      std::messages_byname<wchar_t> wide string message catalog access

      [edit]Nested types

      Type Definition
      catalogstd::messages_base<CharT>::catalog
      string_typestd::basic_string<CharT>

      [edit]Member functions

      (constructor)
      constructs a newmessages_byname facet
      (public member function)[edit]
      (destructor)
      destroys amessages_byname facet
      (protected member function)[edit]
      [edit]

      std::messages_byname::messages_byname

      explicit messages_byname(constchar* name,std::size_t refs=0);
      explicit messages_byname(conststd::string& name,std::size_t refs=0);
      (since C++11)

      Constructs a newstd::messages_byname facet for a locale withname.

      refs is used for resource management: ifrefs==0, the implementation destroys the facet, when the laststd::locale 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
      [edit]

      std::messages_byname::~messages_byname

      protected:
      ~messages_byname();

      Destroys the facet.

      Inherited fromstd::messages

      Nested types

      Type Definition
      char_typeCharT
      string_typestd::basic_string<CharT>

      [edit]Data members

      Member Description
      std::locale::idid[static] the identifier of thefacet

      Member functions

      invokesdo_open
      (public member function ofstd::messages<CharT>)[edit]
      invokesdo_get
      (public member function ofstd::messages<CharT>)[edit]
      invokesdo_close
      (public member function ofstd::messages<CharT>)[edit]

      Protected member functions

      [virtual]
      opens a named message catalog
      (virtual protected member function ofstd::messages<CharT>)[edit]
      [virtual]
      retrieves a message from an open message catalog
      (virtual protected member function ofstd::messages<CharT>)[edit]
      [virtual]
      closes a message catalog
      (virtual protected member function ofstd::messages<CharT>)[edit]

      Inherited fromstd::messages_base

      Nested types

      Type Definition
      catalog an unspecified signed integer type

      [edit]Example

      Run this code
      #include <iostream>#include <locale> void try_with(conststd::locale& loc){conststd::messages<char>& facet=std::use_facet<std::messages<char>>(loc); std::messages<char>::catalog cat= 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);} int main(){std::locale loc("en_US.utf8");std::cout.imbue(loc);     try_with(std::locale(loc, new std::messages_byname<char>("de_DE.utf8")));    try_with(std::locale(loc, new std::messages_byname<char>("fr_FR.utf8")));    try_with(std::locale(loc, new std::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" メモリーが足りません

      [edit]See also

      implements retrieval of strings from message catalogs
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/messages_byname&oldid=178046"

      [8]ページ先頭

      ©2009-2025 Movatter.jp