怎样将cstring型的数型转为char*的数据

解决方案 »

  1.   

    有两种方式,一种是直接访问其字符串,可以使用如下形势
    CString str = "this is a test";
    LPCTSTR lp = (LPCTSTR )str;
    或者:
    char *lp = str.GetBuffer();
      

  2.   

    CString m_med= "this is a test";
    char *str=m_med.GetBufferSetLength(m_med.GetLength());
      

  3.   

    CString csDemo="CString To Char ";
    char *pChar=(LPSTR)(LPCTSTR)csDemo;
      

  4.   

    我觉得lstrcpy不是很好吗? 
    char* buf;
    CString str;
    lstrcpy(buf,str);
      

  5.   

    CString to char *
    //16:56 2003-7-21
    method 1 :
    CString str("xxx");
    char* car = new char[3];
    sprintf(car,"%s",str);
    delete car[];
    method 2:
    CString str("1556666");
    const char* pBuff = (char*)(LPCSTR) str;
    method 3:
    CString str="try";
    char * pBuffer= new char[str.GetLenght()+1]; //GetLenght does not
                                                        // include the '\0'
    strcpy(pBuffer,str);
    delete pBuffer[];