std::btowc
來自 cppreference.com
| 在標頭檔案 <cwchar> 中定義 |
||
| std::wint_t btowc( int c ); |
||
將單位元組字元 c 擴充套件為對應的寬字元。
大多數多位元組字元編碼使用單位元組程式碼表示 ASCII 字元集中的字元。此函式可用於將此類字元轉換為 wchar_t。
目錄 |
[編輯] 引數
| c | - | 要擴充套件的單位元組字元 |
[編輯] 返回值
若 c 是 EOF,則為 WEOF。
若 (unsigned char)c 在初始移位狀態下是有效的單位元組字元,則為 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> 的虛保護成員函式) |
| 有關 btowc 的 C 文件
| |