std::wctob
STD::wctob
Defined in header | | |
---|---|---|
int wctob( std::wint_t c | | |
使宽字变窄c
如果其在初始移位状态下等效的多字节字符是单个字节。
这对于ASCII字符集中的字符来说通常是可能的,因为大多数多字节编码%28(如utf-8%29)使用单个字节来编码这些字符。
参数
c | - | wide character to narrow |
---|
返回值
EOF
如果c
不表示具有长度的多字节字符。1
处于初始移位状态。
否则,c
如unsigned char
转换成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
二次
另见
btowc | widens a single-byte narrow character to wide character, if possible (function) |
---|---|
narrow | narrows characters (public member function of std::basic_ios) |
narrow | invokes do_narrow (public member function of std::ctype) |
C.wctob文件
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。