Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::codecvt<InternT,ExternT,StateT>::encoding, do_encoding

      From cppreference.com
      <cpp‎ |locale‎ |codecvt
       
       
       
      Localization library
       
       
      Defined in header<locale>
      (1)
      public:
      int encoding()constthrow();
      (until C++11)
      public:
      int encoding()constnoexcept;
      (since C++11)
      (2)
      protected:
      virtualint do_encoding()constthrow();
      (until C++11)
      protected:
      virtualint do_encoding()constnoexcept;
      (since C++11)
      1) Public member function, calls the member functiondo_encoding of the most derived class.
      2) If the encoding represented by this codecvt facet maps each internal character to the same, constant number of external characters, returns that number. If the encoding is variable-length (e.g. UTF-8 or UTF-16), returns0. If the encoding is state-dependent, returns-1.

      [edit]Return value

      The exact number ofexternT characters that correspond to oneinternT character, if constant.0 if the number varies,-1 if the encoding is state-dependent.

      The non-converting specializationstd::codecvt<char,char,std::mbstate_t> returns1.

      [edit]Example

      Run this code
      #include <iostream>#include <locale> int main(){std::cout<<"en_US.utf8 is a variable-length encoding, encoding() returns "<<std::use_facet<std::codecvt<wchar_t,char,std::mbstate_t>>(std::locale("en_US.utf8")).encoding()<<'\n'; std::cout<<"zh_CN.gb18030 is also variable-length, encoding() == "<<std::use_facet<std::codecvt<wchar_t,char,std::mbstate_t>>(std::locale("zh_CN.gb18030")).encoding()<<'\n'; std::cout<<"ru_RU.koi8r is a single-byte encoding, encoding() == "<<std::use_facet<std::codecvt<wchar_t,char,std::mbstate_t>>(std::locale("ru_RU.koi8r")).encoding()<<'\n';}

      Output:

      en_US.utf8 is a variable-length encoding, encoding() returns 0zh_CN.gb18030 is also variable-length, encoding() == 0ru_RU.koi8r is a single-byte encoding, encoding() == 1

      [edit]See also

      MB_CUR_MAX
      maximum number of bytes in a multibyte character in the current C locale
      (macro variable)[edit]
      [virtual]
      returns the maximum number ofExternT characters that could be converted into a singleInternT character
      (virtual protected member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/codecvt/encoding&oldid=163334"

      [8]ページ先頭

      ©2009-2025 Movatter.jp