永发信息网

如何将string转化成wchar

答案:1  悬赏:30  手机版
解决时间 2021-03-07 13:02
  • 提问者网友:我一贱你就笑
  • 2021-03-06 22:50
如何将string转化成wchar
最佳答案
  • 五星知识达人网友:从此江山别
  • 2021-03-06 23:47
测试环境: vs2008
开发语言:C++
#include <iostream>
#include <windows.h>
#include <string>

// wchar_t to string
void Wchar_tToString(std::string& szDst, wchar_t *wchar)
{
wchar_t * wText = wchar;
DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE);// WideCharToMultiByte的运用
char *psText; // psText为char*的临时数组,作为赋值给std::string的中间变量
psText = new char[dwNum];
WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE);// WideCharToMultiByte的再次运用
szDst = psText;// std::string赋值
delete []psText;// psText的清除
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯