const char*转换成wstring类型

转载自:https://blog.csdn.net/cqltbe131421/article/details/52597813

直接上代码:

std::wstring CATOW(const char* lpcszString)//返回值类型是wstring类型
{
 int unicodeLen = ::MultiByteToWideChar(CP_ACP, 0, lpcszString, -1, NULL, 0);//获取字符串长度


 wchar_t* pUnicode = new wchar_t[unicodeLen + 1];//开辟宽字节内存
 memset(pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));//清空


 ::MultiByteToWideChar(CP_ACP, 0, lpcszString, -1, (LPWSTR)pUnicode, unicodeLen);//转换
 std::wstring wString = (wchar_t*)pUnicode;//强转后赋值给返回变量
 delete[] pUnicode;
 return wString;
}

猜你喜欢

转载自blog.csdn.net/cyem1/article/details/82670610
今日推荐