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

履歴 編集

function
<locale>

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

state_type state() const;

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

概要

変換の状態を取得する。

戻り値

これによって返される状態は、初期状態か、部分的に変換した状態かのどちらかである。

全ての文字が変換された場合は、初期状態が設定される。

例外

state_type型のコピーコンストラクタが例外を送出しない限り、この関数は例外を送出しない。

#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
#include <cwchar>

int main()
{
  // UTF-8とUTF-32の相互変換を行うコンバーター
  std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;

  std::string input = u8"あいうえお";
  std::u32string result = converter.from_bytes(input);
  std::mbstate_t state = converter.state();

  // 全ての文字が変換された
  if (std::mbsinit(&state) != 0) {
    std::cout << "converted all" << std::endl;
  }
  // 変換されなかった文字がある
  else {
    std::cout << "converted partial" << std::endl;
  }
}

出力

converted all

バージョン

言語

  • C++11

処理系