• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <locale>

    std::wstring_convert::converted

    std::size_t converted() const;          // C++11
    std::size_t converted() const noexcept; // C++14
    

    このクラスはC++17から非推奨となり、C++26で削除された。

    概要

    変換した要素数を取得する。

    戻り値

    from_bytes()もしくはto_bytes()関数で変換した、変換元となった文字列の要素数を返す。

    例外

    投げない。

    #include <iostream>
    #include <string>
    #include <locale>
    #include <codecvt>
    
    int main()
    {
      // UTF-8とUTF-32の相互変換を行うコンバーター
      std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
    
      // UTF-32からUTF-8への変換
      {
        std::u32string input = U"あいうえお";
        std::string u8result = converter.to_bytes(input);
        std::cout << input.size() << " : " << converter.converted() << std::endl;
      }
    
      // UTF-8からUTF-32への変換
      {
        std::string input = u8"あいうえお";
        std::u32string result = converter.from_bytes(input);
        std::cout << input.size() << " : " << converter.converted() << std::endl;
      }
    }
    

    出力

    5 : 5
    15 : 15
    

    バージョン

    言語

    • C++11

    処理系

    • Clang: 3.0 , 3.1 , 3.2 , 3.3 , 3.4
    • GCC: 5.1
    • ICC:
    • Visual C++: 2010 , 2012 , 2013

    参照