you should follow this:CString cstr = "12 hehe";
stringstream ss;
int n;
ss << (const char*)cstr;
ss >>n;

解决方案 »

  1.   

    要把CString 里的字符先取出
    GetBuffer
    CString cstr = "12 hehe";
    stringstream ss;
    int n;
    ss << cstr.GetBuffer();
    ss >>n;
      

  2.   

    hurryboylqs的方法得到:
    error C2440: 'type cast' : cannot convert from 'CString' to 'const char *'gaijiaofan() 的方法得到:n仍然不是我想要的数字,StringBuffer依然乱七八糟。
      

  3.   

    To lz:
     你是不是使用的UNICODE编码?
    如果是,那么就请用下面的方式代替:// VC6: 没有CStringW
    // CString 就是 CStringT
    CString cstr = L"12 hehe";
    wstringstream ss;
    int n;
    ss << L"12 hehe";
    ss >>n;
    // 若为VC7,可以显式使用CStringW
    CStringW cstr = L"12 hehe";
    wstringstream ss;
    int n;
    ss << L"12 hehe";
    ss >>n;
      

  4.   

    Sorry 更正一下:// 若为VC7,可以显式使用CStringW
    CStringW cstr = L"12 hehe";
    wstringstream ss;
    int n;
    ss << (LPCWSTR)cstr;
    ss >>n;
      

  5.   

    后来用了这个:ss << CW2A(cstr); 就好用了
      

  6.   

    my good,unicode那你就转换一下贝,自己本身都用的不是unicode字符当然有问题啦,VC6以后的版本要注意unicode转化,因为它默认的编译方式是unicode,最好用微软提供的转换宏
    比如_T(x),TEXT(x)