std::btowc
提供: cppreference.com
ヘッダ <cwchar> で定義
|
||
std::wint_t btowc( int c ); |
||
シングルバイト文字 c
を同等なワイド文字にワイド化します。
ほとんどのマルチバイト文字エンコーディングは ASCII 文字集合の文字を表すためにシングルバイトのコードを使用します。 この関数はそのような文字を wchar_t に変換するために使用することができます。
目次 |
[編集] 引数
c | - | ワイド化するシングルバイト文字 |
[編集] 戻り値
c
が EOF の場合は WEOF。
(unsigned char)c が初期シフト状態において有効なシングルバイト文字であれば c
のワイド文字表現、そうでなければ WEOF。
[編集] 例
Run this code
#include <iostream> #include <cwchar> #include <clocale> void try_widen(char c) { std::wint_t w = std::btowc(c); if(w != WEOF) std::cout << "The single-byte character " << +(unsigned char)c << " widens to " << +w << '\n'; else std::cout << "The single-byte character " << +(unsigned char)c << " failed to widen\n"; } int main() { std::setlocale(LC_ALL, "lt_LT.iso88594"); std::cout << std::hex << std::showbase << "In Lithuanian ISO-8859-4 locale:\n"; try_widen('A'); try_widen('\xdf'); // German letter ß (U+00df) in ISO-8859-4 try_widen('\xf9'); // Lithuanian letter ų (U+0173) in ISO-8859-4 std::setlocale(LC_ALL, "lt_LT.utf8"); std::cout << "In Lithuanian UTF-8 locale:\n"; try_widen('A'); try_widen('\xdf'); try_widen('\xf9'); }
出力:
In Lithuanian ISO-8859-4 locale: The single-byte character 0x41 widens to 0x41 The single-byte character 0xdf widens to 0xdf The single-byte character 0xf9 widens to 0x173 In Lithuanian UTF-8 locale: The single-byte character 0x41 widens to 0x41 The single-byte character 0xdf failed to widen The single-byte character 0xf9 failed to widen
[編集] 関連項目
可能であればワイド文字をシングルバイト文字に変換します (関数) | |
[仮想] |
文字を char から charT に変換します ( std::ctype<CharT> の仮想プロテクテッドメンバ関数)
|
btowc の C言語リファレンス
|