1、将CString类型转换为string类型:
TCHAR chDir[MAX_PATH];memset(&chDir,0,sizeof(TCHAR)*MAX_PATH);
GetCurrentDirectory(MAX_PATH,chDir);
CString strTemp;
strTemp.Empty();
strTemp.Format(_T("%s"),chDir);
LPTSTR lpsz = new TCHAR[strTemp.GetLength() + 1];
memset(lpsz,0,strTemp.GetLength() + 1);
_tcscpy(lpsz, strTemp);
char *p = new char[(strTemp.GetLength() + 1) * 2];
memset(p, 0, (strTemp.GetLength() + 1) * 2);
WideCharToMultiByte(CP_ACP, 0, lpsz, -1, p, (strTemp.GetLength() + 1) * 2/*strlen(*p)*/, NULL, NULL);
m_stringCurrentDir = p;
2、将TCHAR类型转换为string类型:
做此转换时,可以借用CString作为中间类型,先将TCHAR类型转换为CString类型,然后再将CString类型转换为string类型。