CString str(_T("我是student"));
把str转化成char * p;
???

解决方案 »

  1.   

    char *p=str.GetBuffer(str..GetLength());
    str.ReleaseBuffer();
      

  2.   

    char *p=str.GetBuffer(str.GetLength()); 
    str.ReleaseBuffer();刚多了一个点
      

  3.   


    // unicode to ansi
    CString wszString(_T("我是student")); 
    //预转换,得到所需空间的大小
    int ansiLen = ::WideCharToMultiByte(CP_ACP, NULL, wszString, wcslen(wszString), NULL, 0, NULL, NULL);
    //分配空间要给'\0'留个空间
    char* szAnsi = new char[ansiLen + 1];
    //转换
    ::WideCharToMultiByte(CP_ACP, NULL, wszString, wcslen(wszString), szAnsi, ansiLen, NULL, NULL);
    //最后加上'\0'
    szAnsi[ansiLen] = '\0';
    ::MessageBoxA(NULL, szAnsi, szAnsi, MB_OK);
    delete[] szAnsi;
      

  4.   

    这个是正确的!
    如果在unicode下有可能MessageBox这句不能执行,
    你可以不用MessageBox,在程序里打一个断点就可以看到转换的结果了!