std::wctob - cppreference.com
提供: cppreference.com
<tbody> </tbody>
|
|
||
初期状態における同等なマルチバイト文字がシングルバイトであれば、ワイド文字 c をナロー化します。
これは一般的には ASCII 文字集合の文字に対して可能です。 ほとんどのマルチバイトエンコーディング (UTF-8 など) はこれらの文字のエンコードにシングルバイトを使用します。
引数
戻り値
c が初期シフト状態において長さ 1 のマルチバイト文字を表さない場合は EOF。
そうでなければ、 unsigned char としての c の int に変換されたシングルバイト表現。
例
#include <clocale> #include <cwchar> #include <iostream> void try_narrowing(wchar_t c) { int cn = std::wctob(c); if(cn != EOF) std::cout << '\'' << c << "' narrowed to " << +cn << '\n'; else std::cout << '\'' << c << "' could not be narrowed\n"; } int main() { std::setlocale(LC_ALL, "th_TH.utf8"); std::cout << std::hex << std::showbase << "In Thai UTF-8 locale:\n"; try_narrowing(L'a'); try_narrowing(L'๛'); std::setlocale(LC_ALL, "th_TH.tis620"); std::cout << "In Thai TIS-620 locale:\n"; try_narrowing(L'a'); try_narrowing(L'๛'); }
出力:
In Thai UTF-8 locale: '0x61' narrowed to 0x61 '0xe5b' could not be narrowed In Thai TIS-620 locale: '0x61' narrowed to 0x61 '0xe5b' narrowed to 0xfb