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

std::mbsinit

Defined in header <cwchar>

int mbsinit( const std::mbstate_t* ps);

如果ps不是空指针,则mbsinit函数确定指向std::mbstate_t对象描述初始转换状态。

注记

虽然零初始化std::mbstate_t始终表示初始转换状态,则可能存在其他值。std::mbstate_t它也表示初始转换状态。

参数

ps

-

pointer to the std::mbstate_t object to examine

返回值

​0​如果ps不是空指针,也不重新表示初始转换状态,否则为非零值。

二次

代码语言:javascript
复制
#include <clocale>
#include <string>
#include <iostream>
#include <cwchar>
 
int main()
{
    // allow mbrlen() to work with UTF-8 multibyte encoding
    std::setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    std::string str = u8"水"; // or u8"\u6c34" or "\xe6\xb0\xb4"
    std::mbstate_t mb = std::mbstate_t();
    (void)std::mbrlen(&str[0], 1, &mb);
    if (!std::mbsinit(&mb)) {
        std::cout << "After processing the first 1 byte of " << str
                  << " the conversion state is not initial\n";
    }
 
    (void)std::mbrlen(&str[1], str.size()-1, &mb);
    if (std::mbsinit(&mb)) {
        std::cout << "After processing the remaining 2 bytes of " << str
                  << ", the conversion state is initial conversion state\n";
    }
}

二次

产出:

二次

代码语言:javascript
复制
After processing the first 1 byte of 水 the conversion state is not initial
After processing the remaining 2 bytes of 水, the conversion state is initial conversion state

二次

另见

mbstate_t

conversion state information necessary to iterate multibyte character strings (class)

c mbsinit文件

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

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

扫码关注腾讯云开发者

领取腾讯云代金券