Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::wstring_convert<Codecvt,Elem,Wide_alloc,Byte_alloc>::converted

      From cppreference.com
      <cpp‎ |locale‎ |wstring convert
       
       
       
      Localization library
       
       
      Defined in header<locale>
      std::size_t converted()constnoexcept;

      Returns the number of source characters that were successfully processed by the most recentfrom_bytes() orto_bytes().

      Contents

      [edit]Return value

      cvtcount

      [edit]Example

      Run this code
      #include <codecvt>#include <iostream>#include <locale>#include <string> int main(){std::string utf8="z\u00df\u6c34\U0001d10b";// or u8"zß水𝄋"// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";std::cout<<"original UTF-8 string size: "<< utf8.size()<<'\n'; // the UTF-8 - UTF-32 standard conversion facetstd::wstring_convert<std::codecvt_utf8<char32_t>,char32_t> cvt; // UTF-8 to UTF-32std::u32string utf32= cvt.from_bytes(utf8);std::cout<<"UTF-32 string size: "<< utf32.size()<<'\n';std::cout<<"converted() == "<< cvt.converted()<<'\n'; // UTF-32 to UTF-8    utf8= cvt.to_bytes(utf32);std::cout<<"new UTF-8 string size: "<< utf8.size()<<'\n';std::cout<<"converted() == "<< cvt.converted()<<'\n';}

      Output:

      original UTF-8 string size: 10UTF-32 string size: 4converted() == 10new UTF-8 string size: 10converted() == 4

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2174C++11wstring_convert::converted was not required to be noexceptrequired

      [edit]See also

      converts a wide string into a byte string
      (public member function)[edit]
      converts a byte string into a wide string
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/wstring_convert/converted&oldid=177203"

      [8]ページ先頭

      ©2009-2026 Movatter.jp