C++类型转换 TCHAR转string
2018-06-30 本文已影响0人
刘千予
/******************************************************************************************
Function: TCHAR2STRING
Description: TCHAR转string
Input: str:待转化的TCHAR*类型字符串
Return: 转化后的string类型字符串
*******************************************************************************************/
std::string TCHAR2STRING(TCHAR* str)
{
std::string strstr;
try
{
int iLen = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
char* chRtn = new char[iLen * sizeof(char)];
WideCharToMultiByte(CP_ACP, 0, str, -1, chRtn, iLen, NULL, NULL);
strstr = chRtn;
}
catch (std::exception e)
{
}
return strstr;
}