char * cstr 转换成 cstring str;

解决方案 »

  1.   

    CString str;
    str.Format("%s",cstr);
      

  2.   

    str=cstr;
    反过来
    getbuffer();
      

  3.   

    看你们使用不使用UNICODE了。
    M2CS(char *mchar,CString cs)
    {
    #ifdef _UNICODE
    int nLen = strlen(mchar);
    cs.Empty();
    TCHAR* lpwchar = new TCHAR[nLen * 2 + 1];
    int   iLength ;
    iLength = MultiByteToWideChar (CP_OEMCP, 0, mchar, -1, NULL, 0) ;
    if(iLength<=0)return NULL;
    MultiByteToWideChar (CP_OEMCP, 0, mchar, -1, wchar, iLength+1) ;
    _tcscpy(lpwchar,mchar);
    cs.Format(_T("%s"), lpwchar);
    delete lpwchar;
    #else
    cs.Format(_T("%s"), mchar);
    #endif
    }