比如,我定义了CString s;char* c; 赋值  s.Format("论坛");怎样将s的数据赋到char*地址的内存?
我用过强制转换,但数据不对。比如c = (char*)&s;MessageBox(c)显示的并非“论坛”
高手请举例说明~ 多谢。

解决方案 »

  1.   

    c = s.operator LPCTSTR();
      

  2.   

    CString str(_T("l love you"));
    char ch[100];
    int len=str.GetLegth();
    for(int i=0;i<len,i++)
    {
       ch[i]=str.GetAt(i);
    }
    ch[len]='\0';
      

  3.   

    用(const char*)强制转换可以的。
      

  4.   

    c = s.GetBuffer(255); //255是你字符串的最大长度可以用s.GetLength
    s.ReleaseBuffer();
      

  5.   

    CString s1 = ……;
    char* s2 = new char[s1.GetLength() + 1];
    strcpy(s2 , s1);
    ……
    delete[] s2;
    ……
      

  6.   

    CString szData("hello");
    char* pszData = szData.GetBuffer(0);