Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
char *ptr = "0.3312015";

I want to get "0.3312015" and convert to double type,
*ptr can only get the first char 0,
how to write this program?
thanks for answer.
Posted

Use the atof[^] function: that is what it is there for!
 
Share this answer
 
Comments
CPallini 31-Oct-14 10:00am    
5. The C way.
Use a std::istringstream or std::istrstream (if you can cope with the axe of deprecation that's been hanging over the latter since 1998). You can read stuff in from that array the same way you can from cin.
 
Share this answer
 
Comments
CPallini 31-Oct-14 10:01am    
5. The C++ way.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900