这个 mbsinit() 是C++中的一个内置函数,用来检查是否 附言 (作为参数传递到此函数)指向描述初始转换状态的mbstate_t对象。对于表示初始状态的任何mbstate_t对象,或者如果ps是空指针,此函数将返回非零。 ps指向的状态可以通过调用以下命令设置为初始状态:
null
// ps points now to a zero-valued objectmemset (ps, 0, sizeof(*ps));
语法:
int mbsinit( const mbstate_t* ps)
参数: 该函数接受一个参数,如下所述:
- 附言: 指向mbstate_t对象的指针
返回值: 函数返回两个值,如下所示:
- 如果ps不是空指针且不代表初始转换状态,则为0。
- 如果ps是空指针或表示初始转换状态,则为非零。
以下程序说明了上述功能: 项目1:
CPP
// C++ program to illustrate // mbsinit() function #include <bits/stdc++.h> using namespace std; // function to check if the object describes // the initial conversion state void checkfor( mbstate_t ps) { // (mbstate_t) Type that holds the information necessary // to maintain the state when converting between // sequences of multibyte characters and // wide characters (either way). int func = mbsinit(&ps); if (func) cout<< "The conversion state is initial" << " conversion state" ; else cout<< "The conversion state is not initial" << " conversion state" ; } // Driver code int main() { setlocale (LC_ALL, "en_US.utf8" ); // initializing the string char str[] = "u00df" ; // initial state mbstate_t ps = mbstate_t (); // check if ps is liknked to // initial conversion state checkfor(ps); mbrlen(str, 1, &ps); // check if, after getting the // length of multibyte character checkfor(ps); return 0; } |
输出:
The conversion state is initial conversion stateThe conversion state is not initial conversion state
项目2:
CPP
// C++ program to illustrate // mbsinit() function // with empty string #include <bits/stdc++.h> using namespace std; // function to check if // object describes the initial conversion state void checkfor( mbstate_t ps) { // (mbstate_t) Type that holds the information necessary // to maintain the state when converting between // sequences of multibyte characters and // wide characters (either way). int func = mbsinit(&ps); if (func) cout << "the conversion state is initial" << " conversion state" ; else cout << "the conversion state is not initial" << " conversion state" ; } // Driver code int main() { setlocale (LC_ALL, "en_US.utf8" ); // initializing the string char str[] = "" ; // initial state mbstate_t ps = mbstate_t (); // check if ps is liknked to // initial conversion state cout << "After ps is initialized, " ; checkfor(ps); mbrlen(str, 0, &ps); // check if, after getting the // length of multibyte character cout << "After performing some task, " ; checkfor(ps); return 0; } |
输出:
After ps is initialized, the conversion state is initial conversion stateAfter performing some task, the conversion state is initial conversion state
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END