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
 */怎么改正呢?

解决方案 »

  1.   

    char sc[20];
    CString ss = "test";
    ss.GetBuffer(20);
    strcpy(sc, ss); 
    这样就可以了!
      

  2.   

    方法如下
    sprintf(sc,"%s",ss);
      

  3.   

    有个问题我觉得非常奇怪:CString ss;
    char sc[20];ss.Format("%s", sc);我有时在一个工程里面使用完全没有问题,但是在另外一个工程里面则编译出错:
     error C2664: 'GetErrorMessage' : cannot convert parameter 1 from 'char [20]' to 'unsigned short *'怎么搞的?????????
      

  4.   

    _UNICODE宏导致的
    CString目前是wchar_t
    自然不能直接用strcpy
    要用_tcscpy,或去掉_UNICODE
      

  5.   

    这样去掉_UNICODE 吗?
    #ifdef _UNICODE 
    #undef _UNICODE
    #endif
      

  6.   

    不能这么简单的去掉
    而是应该 工程-> 设置->C/C++ C预处理器中去掉_UNICODE 字段就可以了