首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::btowc

Defined in header <cwchar>

std::wint_t btowc( int c );

扩展单字节字符。c与它的宽特性相当。

大多数多字节字符编码使用单字节代码来表示ASCII字符集中的字符。此函数可用于将这些字符转换为wchar_t...

参数

c

-

single-byte character to widen

返回值

WEOF如果cEOF...

宽字符表示c如果(unsigned char)c是处于初始移位状态的有效单字节字符,WEOF否则。

二次

代码语言:javascript
复制
#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');
}

二次

产出:

二次

代码语言:javascript
复制
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

二次

另见

wctob

narrows a wide character to a single-byte narrow character, if possible (function)

do_widen virtual

converts a character or characters from char to charT (virtual protected member function of std::ctype)

c btwc文件

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券