Monday, July 27, 2009

Why is my Visual C++ code not working?

My code is:





double d = atof(str);





This produces an error "cannot convert CString to const char*"


even if I include required header files %26lt;math.h%26gt; and %26lt;stdlib.h%26gt;





In other application i was able to make this code work.


What would be the reason for this?


Am I missing something?





Hoping for your comments. Thank you.

Why is my Visual C++ code not working?
in vc++, explicit conversion is to be done.


char* p=(char*)str;





do double d=atof(p);


it must work
Reply:You seem to be getting confused between C and C++. C doesn't have a CString type, just char [] and char *, but in C++, you're dealing with objects and have to use methods to get the value you need for compatibility.





As for why your code is being treated as C++, there may be something else in it that we're not seeing, which is incompatible with the use of C.
Reply:str needs to be const char* not Cstring


look at the CString docs for somethign that does a conversion...like .c_str() or similar


No comments:

Post a Comment