方法一:

char *p;

CString str="hello";

p=str.GetBuffer(str.GetLength());

str.ReleaseBuffer();


方法二:

CString str="hello";

char ch[20];

memcpy(ch,str,str.GetLength());


注意:

如果是声明一个char类型的数组,一定要初始化。否则后面未使用的字节为乱码。

//拼接文件存放路径、文件名、后缀

CString FileDir;

if(m_shanlingpath.GetLength()>4)

FileDir = m_shanlingpath + "\\" + m_shanlingname + "." + FilePostfix;

else

FileDir = m_shanlingpath + m_shanlingname + "." + FilePostfix;

char filename[64] = {0 }; //注意初始化

memcpy(filename,FileDir,FileDir.GetLength());


方法三:

char *ch;

CString str="hello";

ch=(LPSTR)(LPCTSTR)str;