请问如何将const char*转变成CString类型的Unicode Charaset

解决方案 »

  1.   

    直接赋值给一个CString变量,要做参数传递的话那就传递一个const CString对象~
      

  2.   

    还有。。这个好像不能直接转吧。。const Char*都不可能提供这种转换操作
    从CString到const Char*倒是可以。。
      

  3.   

    //const char *szText;
    CString strText = szText;//或者
    strText.Format(L"%s",szText);
      

  4.   

    char 转 CString  
    CString.format("%s", char*);  
      

  5.   

    CString 和 LPCTSTR 可以说通用。 原因在于CString定义的自动类型转换,没什么奇特的,最简单的C++操作符重载而已。
    LPCTSTR == const TCHAR *
      

  6.   

    error C2440: '<function-style-cast>' : cannot convert from 'const char *' to 'ATL::CW2W'
      

  7.   


    error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *
      

  8.   

    你在unicode工程里面不要用char*
    这个时候CString是使用的unicode,你传char*当然失败~
      

  9.   

    TCHAR a[]=_T("3123");
    CString str;
    str.Format(_T("%s"),a);
      

  10.   

    在Unicode的工程里面不要使用char*,建议在工程中使用TCHAR。如果你非要用char,得先用MultiByteToWideChar函数转成LPWSTR宽字符指针,然后再赋值。
      

  11.   


    怎么用MultiByteToWideChar,帮帮忙
      

  12.   

    const char* c;
    c = "abcdef";
    CString s;
    int len = strlen(c);
    TCHAR* c1 = (TCHAR*)malloc(sizeof(TCHAR)*len);
    MultiByteToWideChar( CP_ACP , 0 , c , len+1 , c1 , len+1);
    s.Format(L"%s",c1);