小编D.A*_*ANG的帖子

如何将wstring转换为u16string?

我想转换wstringu16stringC ++。

我可以转换wstring为字符串,也可以反转。但我不知道如何转换为u16string

u16string CTextConverter::convertWstring2U16(wstring str)

{

        int iSize;
        u16string szDest[256] = {};
        memset(szDest, 0, 256);
        iSize = WideCharToMultiByte(CP_UTF8, NULL, str.c_str(), -1, NULL, 0,0,0);

        WideCharToMultiByte(CP_UTF8, NULL, str.c_str(), -1, szDest, iSize,0,0);
        u16string s16 = szDest;
        return s16;
}
Run Code Online (Sandbox Code Playgroud)

WideCharToMultiByte(CP_UTF8,NULL,str.c_str(),-1,szDest,iSize,0,0);中的错误szDestu16string无法与使用的原因LPSTR

如何解决此代码?

c++ winapi utf-16 wstring valueconverter

4
推荐指数
1
解决办法
4776
查看次数

标签 统计

c++ ×1

utf-16 ×1

valueconverter ×1

winapi ×1

wstring ×1