error C2440: '=': cannot convert from 'char *' to 'PCZZWSTR'

强颜欢笑 提交于 2019-12-18 11:41:08

方法一:

字符集转换: utf8 to uni.

std::wstring utf8_to_uni(const char *in)
{
    return _to_uni(CP_UTF8, in);   // ansi to uni: CP_ACP
}

std::wstring _to_uni(unsigned int acp, const char *lpa)
{
    int nChars = strlen(lpa)+1;
    wchar_t *lpw = new wchar_t[nChars];
    lpw[0] = 0;

    int ret = MultiByteToWideChar(acp, 0, lpa, -1, lpw, nChars);
    if(ret == 0)
    {
        delete []lpw;
        return L"";
    }

    std::wstring wstrlpw = lpw;
    delete []lpw;
    return wstrlpw;
}

方法二:

打开工程属性面板:"General" -> "Character Set"  设置为:"Use Multi-Byte Character Set" 。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!