宽字节wchar_t* 转换 单字节char*

来源:互联网 发布:全钢网络地板 编辑:程序博客网 时间:2024/05/22 16:56
// 将 宽字节wchar_t* 转换 单字节char*
inline std::string UnicodeToAnsi( const wchar_t* szStr )
{
int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL );
if (nLen == 0)
{
  return NULL;
}
//char* pResult = new char[nLen];
std::string res;
res.resize(nLen);
WideCharToMultiByte( CP_ACP, 0, szStr, -1, (char*)res.c_str(), nLen, NULL, NULL );
return res;

}