📅  最后修改于: 2020-09-25 09:37:30             🧑  作者: Mango
mbsrtowcs() 函数在
size_t mbsrtowcs( wchar_t* dest, const char** src, size_t len, mbstate_t* ps );
所述mbsrtowcs() 函数将多字符 字符串 ,其第一个字节被表示为*src
到对应的宽字符表示,并且被存储在宽字符阵列中由指向dest
。最多可将len
宽字符写入dest
。
转换过程类似于重复调用mbrtowc()。如果发生以下情况,转换将停止:
#include
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.utf8");
const char* str = "\u0763\u0757\u077f\u075f";
wchar_t wstr[20];
mbstate_t ps = mbstate_t();
int len = 10;
int retVal;
retVal = mbsrtowcs(wstr, &str, len, &ps);
wcout << L"Number of wide characters written (excluding L\"\\0\") = " << retVal << endl;
wcout << L"Wide character = " << wstr << endl;
return 0;
}
运行该程序时,输出为:
Number of wide characters written (excluding L"\0") = 4
Wide character = ݣݗݿݟ