程序是在visual studio 2005里写的cstring str(“12.33”);
float value = atof(str);原来用atof可以转化,在visual studio 2005里不知道怎么搞的出现下面的错误
'atof' : cannot convert parameter 1 from 'CString' to 'const char *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
请高手指教一下,谢谢大家了,最好具体些

解决方案 »

  1.   

    float value = atof(str.GetBuffer());
    str.ReleaseBuffer();
      

  2.   

    JOKER_FISH  照你的修改  
    还是出现如下的错误:
    error C2664: 'atof' : cannot convert parameter 1 from 'wchar_t *' to 'const char *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
      

  3.   

    是在visual studio 2005 里执行的时候不行在visual studio 2005转成整型要用
    int values = _ttoi(newstring);
    用atoi()转化是不行,请高手指点呀
    谢谢
    在线等待。
      

  4.   

    float value = atof((LPCTSTR)(LPSTR)str);
      

  5.   

    这个错误是因为你的工程使用的的UNICODE编译才会如此的如果你用MUTIBYTE编译就不会出现这个问题_ttoi就是为了兼容UNICODE与非UNICODE设计的
      

  6.   

    CString str(“12.33”); 
    float value = atof((LPCTSTR)str); //atof函数的参数是const char *类型
      

  7.   

    atof 如果你一定想用的话你要先将CString 转成 MutiByte才可以 也就是char先用WideCharTOMutiByte把宽字符的CString转成窄字符然后再使用atof
      

  8.   

    不要直接使用 atox() ,因为明明有 ttox就好像不用 windows api 的 xxxxxA xxxxW 一样
      

  9.   

    CString temp = "10.2";
    float ss = atof(temp.GetBuffer(0));
      

  10.   

    你要先把CString转换为字符数组 然后才能用atof,
      

  11.   

    这是因为用了UNICODE的缘故,需要将宽字节转化为多字节后才能转换,可以这样写:USES_CONVERSION;
    LPCSTR _str = W2A(str);   // str为CString类型
    float fValue = atof(_str);
      

  12.   

    谢谢大家,结贴 特此谢谢 zhouzhenyan 
    周曹俊(周桢焱)