直接上代码:

std::string CWTOA(const wchar_t* lpwcszWString)
{
char* pElementText;//定义一个char类型指针
int iTextLen;//定义长度

iTextLen = ::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, -1, NULL, 0, NULL, NULL);//获取传入字符串长度 pElementText = new char[iTextLen + 1];//开辟空间
memset((void*)pElementText, 0, (iTextLen + 1) * sizeof(char));//清空 ::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, -1, pElementText, iTextLen, NULL, NULL);//转换
std::string strReturn(pElementText);//定义string类型变量,以构造的方式传入字符串赋值
delete[] pElementText;
return strReturn;//返回你懂的;