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

履歴 編集

function
<locale>

std::wstring_convert::converted(C++11)(C++17で非推奨)

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

このクラスはC++17から非推奨となった。

概要

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

戻り値

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

処理系

参照