方法一:
char *p;
CString str="hello";
p=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
方法二:
CString str="hello";
char ch[20];
memcpy(ch,str,str.GetLength());
方法三:
char *ch;
CString str="hello";
ch=(LPSTR)(LPCTSTR)str;
以上三种方法都可以的.
//
如何把TCHAR*转为char*
首先你必须判断当前是否使用了unicode,如果是用了unicode
那么就需要使用wcstombs来进行转化,
char* pDest = NULL;
#ifdef _UNICODE
pDest = (char*)malloc(wcslen(pSrc) + 1);
wcstombs(pDest, pSrc, wcslen(pSrc));
#else
pDest = (char*)malloc(strlen(pSrc) + 1);
strcpy(pDest, pSrc);
#endif