请问如何将'class CString *'转化为'const char *',多谢了

解决方案 »

  1.   

    class CString* tmpStr;
    const char* tmpsz = LPCTSTR(*tmpStr)
      

  2.   

    CString * str = "hello world!";
    str->GetBuffer();
      

  3.   

    注意Unicode转换要用WideCharToMultiByte
      

  4.   

    LPCTSTR(yourCString); 足以, 在ANSI转化出来就是char *. Unicode下是wchar_t.
      

  5.   

    用LPCTSTR指针
    例如:
       CString a;
       a="abc";
       char *b;
       b=(LPCTSTR)a;
       
    这时b中都数据时"abc"
      

  6.   

    reinterpret_cast Operator
    C++ Specific —>reinterpret_cast < type-id > ( expression )The reinterpret_cast operator allows any pointer to be converted into any other pointer type, and it allows any integral type to be converted into any pointer type and vice versa. Misuse of the reinterpret_cast operator can easily be unsafe. Unless the desired conversion is inherently low-level, you should use one of the other cast operators.END C++ Specific
      

  7.   

    const char* szText;
    CString str("aaa"); szText = str.GetBuffer(str.GetLength());
      

  8.   

    getbuffer()之后还要
    releasebuffer()
      

  9.   

    对于Ansi的CString,(char*)((LPCTSTR)str)
    否则的话可能要用WideCharToMultiBytes