为了账号安全,请及时绑定邮箱和手机立即绑定

如何在C ++(Unicode)中将std :: string转换为LPCWSTR

如何在C ++(Unicode)中将std :: string转换为LPCWSTR

C++
繁华开满天机 2019-11-12 10:10:40
我正在寻找将std :: string转换为LPCWSTR的方法或代码段
查看完整描述

3 回答

?
梵蒂冈之花

TA贡献1900条经验 获得超5个赞

std::wstring s2ws(const std::string& s)

{

    int len;

    int slength = (int)s.length() + 1;

    len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); 

    wchar_t* buf = new wchar_t[len];

    MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);

    std::wstring r(buf);

    delete[] buf;

    return r;

}


std::wstring stemp = s2ws(myString);

LPCWSTR result = stemp.c_str();


查看完整回答
反对 回复 2019-11-12
  • 3 回答
  • 0 关注
  • 969 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信