CString 怎么转化成char[]型的

解决方案 »

  1.   

    CString::GetBuffer(CString::GetLength());
      

  2.   

    char * = CString::GetBuffer(0);
    char [0] = char *
      

  3.   

    多字节就CString::GetBuffer(0)
    unicode的话再把CString::GetBuffer(0)得到的宽字节转成char []
    \WideCharToMultiByte等转
      

  4.   

    #include <atlbase.h>
    USES_CONVERSION;
    char* buf = T2A(...);
      

  5.   

    USES_CONVERSION;
    strcpy_s(char *buff,strlen(buff),T2A(CString str));
      

  6.   

    strncpy_s(c.chName, _countof(c.chName), (LPCTSTR)strText, strlen(c.chName));
      

  7.   

    CString str;
    TCHAR   tempchar[200];lstrcpy(tempchar,str);
      

  8.   

    还是用GetBuffer比较简单吧不过使用了GetBuffer后,要调用ReleaseBuffer 释放一下;CString TagName("demo");
    char *tmp = TagName.GetBuffer( 0 );
    TagName.ReleaseBuffer();
      

  9.   

    提示说:cannot convert from 'wchar_t *' to 'char *‘
    是不是Unicode下GetBuffer不能使?
      

  10.   

    str.GetBuffer提示有错误啊?
    cannot convert from 'wchar_t *' to 'char *‘
      

  11.   

    解决了。用的这种方法:
    CString strSendBuf;
    char SendBuf[100];
    TCHAR tempchar[200];
    lstrcpy(tempchar,strSendBuf);
    int nLength   =   WideCharToMultiByte(CP_ACP,0,tempchar,-1,NULL,0,NULL,NULL);   
    WideCharToMultiByte(CP_ACP,0,tempchar,-1,SendBuf,nLength,NULL,NULL); 
    是不是超级笨的方法。
    但是我现在对那个WCHAR,TCHAR,UNICODE,ASCAII,一点概念都没有。。
    谁有这方面的书,推荐看看
      

  12.   

    你的方法不笨
    unicode就是这样搞的
    WideCharToMultiByte
    这个函数可以将宽字符转换为多字节字符
    WCHAR THCAR 是宽字符
    char是窄字符
    Windows程序设计 和 Windows核心编程最开始的部分
    对Unicode讲解的很清楚
    你可以下载一本电子书看一下
    一个小时吧
    可以把这块搞的很清楚
    核心编程中也讲了WideCharToMultiByte这个函数的使用
    我经常要写wince下的程序
    wince下就支持unicode
    unicode是16位,可以表示65536个字符
    这样就能表示包括中文,英文,韩文等等
    如果只是ASCII码等8位的能表示的字符太少了。
    ... ...
      

  13.   

    wchar_T

    typedef unsigned short wchar_t;
      

  14.   

    -----------------------------------
    看看我整理摘录的
    http://blog.csdn.net/shihaojie1219/archive/2010/07/29/5775041.aspx
    http://blog.csdn.net/shihaojie1219/archive/2010/07/28/5770692.aspx