class template
std::codecvt
namespace std {
template <class internT, class externT, class stateT>
class codecvt : public locale::facet, public codecvt_base;
}
概要
codecvtは、内部型internTの文字列と外部型externTの文字列を相互に変換するためのロケールファセットである。
basic_filebufは、ファイル上のバイト列(外部型)とプログラム上の文字列(内部型)の変換にこのファセットを使用する。
stateTは変換の状態を保持する型であり、状態依存のエンコーディングを扱うために使用される。
メンバ関数
publicメンバ関数
静的メンバ変数
protectedメンバ関数
メンバ型
| 名前 |
説明 |
intern_type |
内部型 internT |
extern_type |
外部型 externT |
state_type |
変換の状態を表す型 stateT |
例
#include <iostream>
#include <locale>
#include <cwchar>
int main()
{
using codecvt_t = std::codecvt<wchar_t, char, std::mbstate_t>;
const auto& cv = std::use_facet<codecvt_t>(std::locale::classic());
const char from[] = "abc";
wchar_t to[4] = {};
std::mbstate_t state{};
const char* from_next = nullptr;
wchar_t* to_next = nullptr;
// 外部型(char)から内部型(wchar_t)へ変換する
codecvt_t::result r = cv.in(state, from, from + 3, from_next, to, to + 3, to_next);
*to_next = L'\0';
std::cout << std::boolalpha << (r == codecvt_t::ok) << std::endl;
std::wcout << to << std::endl;
}
出力
true
abc
バージョン
言語
関連項目