char sc[20];
CString ss = "test";
strcpy(sc, ss);
/*
编译提示出错:
error C2664: 'strcpy' : cannot convert parameter 2 from 'class CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
*/
strcpy(sc,ss.Operator LPCTSTR());
/*
编译提示出错:
error C2664: 'strcpy' : cannot convert parameter 2 from 'const unsigned short *' to 'const char *' ,Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
*/怎么改正呢?
CString ss = "test";
strcpy(sc, ss);
/*
编译提示出错:
error C2664: 'strcpy' : cannot convert parameter 2 from 'class CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
*/
strcpy(sc,ss.Operator LPCTSTR());
/*
编译提示出错:
error C2664: 'strcpy' : cannot convert parameter 2 from 'const unsigned short *' to 'const char *' ,Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
*/怎么改正呢?
CString ss = "test";
ss.GetBuffer(20);
strcpy(sc, ss);
这样就可以了!
sprintf(sc,"%s",ss);
char sc[20];ss.Format("%s", sc);我有时在一个工程里面使用完全没有问题,但是在另外一个工程里面则编译出错:
error C2664: 'GetErrorMessage' : cannot convert parameter 1 from 'char [20]' to 'unsigned short *'怎么搞的?????????
CString目前是wchar_t
自然不能直接用strcpy
要用_tcscpy,或去掉_UNICODE
#ifdef _UNICODE
#undef _UNICODE
#endif
而是应该 工程-> 设置->C/C++ C预处理器中去掉_UNICODE 字段就可以了