vs2008下几个CString转换char*的问题
几个CString转换的问题,这个问题折磨了我两天的,以下代码是我参考网上给出的n种方法,居然没有一个可以的,看来我的vs2008进步了很多!
char *p_list = NULL;
char *p_ins = NULL;
char *p_temp =NULL;
char tlist[100];
CString s("This is a test");
//way1: CString to char*
p_list = (LPTSTR)(LPCTSTR)s;
//VS2008 compile error: 无法从“LPTSTR”转换为“char *”
//way2: CString to char*
p_temp= s.GetBuffer(0);
strcpy(p_list,p_temp);//CString->char*
s.ReleaseBuffer(-1);
//VS2008 compile error: 无法从“wchar_t *”转换为“char *”
//way2: CString to char*
p_temp= s.GetBuffer(s.GetLength());
strcpy(p_list,p_temp);//CString->char*
s.ReleaseBuffer();
//VS2008 compile error: 无法从“wchar_t *”转换为“char *”
//way3:
p_list = (char*)s;
//error:无法从“CString”转换为“char *”
//way4:
p_list= new char[s.GetLength()+1];
strcpy(p_list,(LPCSTR)s);
//error:无法从“CString”转换为“LPCSTR”
//CString to char[]
strcpy(tlist,(char *)(const char*)s);
//VS2008 compile error: 无法从“CString”转换为“const char *”