📜  C++ mbsinit()

📅  最后修改于: 2020-09-25 09:36:08             🧑  作者: Mango

C++中的mbsinit() 函数确定mbstate_t对象是否描述了初始转换状态。

mbsinit() 函数在头文件中定义。

mbsinit()原型

int mbsinit( const mbstate_t* ps);

如果ps不是空指针,则mbsinit() 函数检查ps是否表示初始转换状态。

mbsinit()参数

mbsinit()返回值

mbsinit() 函数返回:

示例:mbsinit() 函数如何工作?

#include 
#include 
#include 
using namespace std;

void test_ps(mbstate_t ps)
{
    if (mbsinit(&ps))
    cout << "the conversion state is initial conversion state" << endl;
    else
    cout << "the conversion state is not initial conversion state" << endl;
}

int main()
{
    setlocale(LC_ALL, "en_US.utf8");
    
    char str[] = "\u00b5";
    mbstate_t ps = mbstate_t();
    
    cout << "Initially after creating ps, ";
    test_ps(ps);
    mbrlen(str, 1, &ps);
    
    cout << "After performing some task, ";
    test_ps(ps);
    
    return 0;
}

运行该程序时,输出为:

Initially after creating ps, the conversion state is initial conversion state
After performing some task, the conversion state is not initial conversion state