这个 wcsrtombs() 函数将宽字符转换为多字节字符串。此函数用于转换由表示的宽字符串 *src 对应的多字节字符串,并存储在 目的地 如果 目的地 不是空的。最多 伦恩 字符被写入 目的地 . 语法:
null
大小WCSRM(字符*目的地,常量wchar**src,大小长度,mbstate*ps)
参数: 该函数接受四个强制参数,如下所述:
- 目的地: 指向字符元素数组的指针,其长度足以存储一个最大字节字符串
- src: 指向要翻译的宽字符串的指针
- 伦恩: dest数组中可用的最大字节数
- 附言: 指向转换状态对象的指针
返回值: 该函数返回两个值,如下所示:
- 成功返回写入dest的字节数(不包括最终终止的空字符)
- 如果出现错误,则返回-1,并将errno设置为 艾尔斯克 .
以下程序说明了上述功能: 项目1:
CPP
// C++ program to illustrate // wcsrtombs() function #include <bits/stdc++.h> using namespace std; int main() { // initialize the string const wchar_t * src = L "Geekforgeeks" ; // maximum length of the dest char dest[20]; // initial state mbstate_t ps = mbstate_t (); // maximum length of multibyte character int len = 12; // function to convert wide-character // to multibyte string int value = wcsrtombs(dest, &src, len, &ps); cout << "Number of multibyte characters = " << value << endl; cout << "Multibyte characters written = " << dest << endl; return 0; } |
输出:
Number of multibyte characters = 12Multibyte characters written = Geekforgeeks
项目2:
CPP
// C++ program to illustrate // wcsrtombs() function #include <bits/stdc++.h> using namespace std; int main() { // initialize the string const wchar_t * src = L "This website is the best" ; // maximum length of the dest char dest[20]; // initial state mbstate_t ps = mbstate_t (); // maximum length of multibyte character int len = 14; // function to convert wide-character // to multibyte string int value = wcsrtombs(dest, &src, len, &ps); cout << "Number of multibyte characters = " << value << endl; cout << "Multibyte characters written = " << dest << endl; return 0; } |
输出:
Number of multibyte characters = 14Multibyte characters written = This website i
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END