std:: btowc
|
ヘッダー
<cwchar>
で定義
|
||
|
std::
wint_t
btowc
(
int
c
)
;
|
||
単一バイト文字 c をワイド文字表現に変換します。
ほとんどのマルチバイト文字エンコーディングは、ASCII文字セットの文字を表現するためにシングルバイトコードを使用します。この関数は、そのような文字を wchar_t に変換するために使用できます。
目次 |
パラメータ
| c | - | ワイド文字に変換するシングルバイト文字 |
戻り値
WEOF が c が EOF の場合。
c のワイド文字表現。 ( unsigned char ) c が初期シフト状態における有効な単一バイト文字である場合、それ以外の場合は WEOF 。
例
#include <clocale> #include <cwchar> #include <iostream> 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
関連項目
|
ワイド文字を可能であれば単一バイトのナロー文字に変換する
(関数) |
|
|
[virtual]
|
文字または文字列を
char
から
CharT
に変換する
(
std::ctype<CharT>
の仮想保護メンバ関数)
|
|
Cドキュメント
for
btowc
|
|