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不是空指针,也不重新表示初始转换状态,否则为非零值。
例
二次
#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";
}
}二次
产出:
二次
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文件
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

