std::wctob
提供: cppreference.com
ヘッダ <cwchar> で定義
|
||
int wctob( std::wint_t c ); |
||
初期状態における同等なマルチバイト文字がシングルバイトであれば、ワイド文字 c
をナロー化します。
これは一般的には ASCII 文字集合の文字に対して可能です。 ほとんどのマルチバイトエンコーディング (UTF-8 など) はこれらの文字のエンコードにシングルバイトを使用します。
目次 |
[編集] 引数
c | - | ナロー化するワイド文字 |
[編集] 戻り値
c
が初期シフト状態において長さ 1 のマルチバイト文字を表さない場合は EOF。
そうでなければ、 unsigned char としての c
の int に変換されたシングルバイト表現。
[編集] 例
Run this code
#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
[編集] 関連項目
可能であればシングルバイト文字をワイド文字に変換します (関数) | |
文字をナロー化します ( std::basic_ios<CharT,Traits> のパブ��ックメンバ関数)
| |
do_narrow を呼びます ( std::ctype<CharT> のパブリックメンバ関数)
| |
wctob の C言語リファレンス
|