Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::messages<CharT>::open,std::messages<CharT>::do_open

      From cppreference.com
      <cpp‎ |locale‎ |messages
       
       
       
      Localization library
       
       
      Defined in header<locale>
      public:
      catalog open(conststd::string& name,conststd::locale& loc)const;
      (1)
      protected:
      virtual catalog do_open(conststd::string& name,conststd::locale& loc)const;
      (2)
      1) Public member function, calls the protected virtual member functiondo_open of the most derived class.
      2) Obtains a value of typecatalog (inherited fromstd::messages_base), which can be passed toget() to retrieve messages from the message catalog named byname. This value is usable until passed toclose().

      Contents

      [edit]Parameters

      name - name of the message catalog to open
      loc - a locale object that provides additional facets that may be required to read messages from the catalog, such asstd::codecvt to perform wide/multibyte conversions

      [edit]Return value

      The non-negative value of typecatalog that can be used withget() andclose(). Returns a negative value if the catalog could not be opened.

      [edit]Notes

      On POSIX systems, this function call usually translates to a call tocatopen(). In GNU libstdc++, it callstextdomain.

      The actual catalog location is implementation-defined: for the catalog"sed" (message catalogs installed with the Unix utility'sed') in German locale, for example, the file opened by this function call may be/usr/lib/nls/msg/de_DE/sed.cat,/usr/lib/locale/de_DE/LC_MESSAGES/sed.cat, or/usr/share/locale/de/LC_MESSAGES/sed.mo.

      [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.

      Run this code
      #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";elsestd::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);}

      Possible output:

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

      [edit]See also

      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/messages/open&oldid=179772"

      [8]ページ先頭

      ©2009-2025 Movatter.jp