Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::messages<CharT>::get,std::messages<CharT>::do_get

      From cppreference.com
      <cpp‎ |locale‎ |messages
       
       
       
      Localization library
       
       
      Defined in header<locale>
      public:
      string_type get( catalog cat,int set,int msgid,const string_type& dfault)const;
      (1)
      protected:
      virtual string_type do_get( catalog cat,int set,int msgid,const string_type& dfault)const;
      (2)
      1) Public member function, calls the protected virtual member functiondo_get of the most derived class.
      2) Obtains a message from the open message catalogcat using the valuesset,msgid anddfault in implementation-defined manner. If the expected message is not found in the catalog, returns a copy ofdfault.

      Contents

      [edit]Parameters

      cat - identifier of message catalog obtained fromopen() and not yet passed toclose()
      set - implementation-defined argument, message set in POSIX
      msgid - implementation-defined argument, message id in POSIX
      dfault - the string to look up in the catalog (if the catalog uses string look-up) and also the string to return in case of a failure

      [edit]Return value

      The message from the catalog or a copy ofdfault if none was found.

      [edit]Notes

      On POSIX systems, this function call usually translates to a call tocatgets(), and the parametersset,msgid, anddfault are passed tocatgets() as-is. In GNU libstdc++, this function ignoresset andmsgid and simply calls GNUgettext(dfault) in the required locale.

      [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/get&oldid=159027"

      [8]ページ先頭

      ©2009-2025 Movatter.jp