直接上代码:
string cstr2str(const CString &cStr)
{char pszResult[2048] = {0};
int n = cStr.GetLength();
int len = WideCharToMultiByte(CP_ACP,0,cStr,cStr.GetLength(),NULL,0,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,cStr,cStr.GetLength(),pszResult,len,NULL,NULL);
pszResult[len+1] = '\0';
return pszResult;
}
CString str2cstr(const string &str)
{
WCHAR wszResult[2048] = {0};
int len = MultiByteToWideChar(CP_ACP,0,str.c_str(),str.length(),NULL,0);
MultiByteToWideChar(CP_ACP,0,str.c_str(),str.length(),wszResult,len);
wszResult[len+1] = '\0';
return wszResult;
}