|
|
Subject:
type cast
Category: Computers > Programming Asked by: eksolutions-ga List Price: $2.00 |
Posted:
12 Nov 2002 18:28 PST
Expires: 12 Dec 2002 18:28 PST Question ID: 106533 |
I need the answer of this question in C++ code. Let's say you have: char* value = "0.010"; double dValue; How can you convert char* value to double dValue? |
|
Subject:
Re: type cast
Answered By: skermit-ga on 12 Nov 2002 18:52 PST Rated: |
Hello, You can't just typecast change the string to double. Instead you have to use a function in the stdlib.h for string conversion to a double. From my trusty Deitel & Deitel C++ book (the best I think I've ever used): " Function atof converts its argument -- a string that represents a floating point number -- to a double value. " The prototype on page 824 is: double atof( const char *nPtr ) // Converts the string nPtr to double So your usage would have to have an #include <stdlib.h> at the top of your program and then stick this in the logic: char* value = "0.010"; double dValue; dValue = atof( value ); You could shorten the 2nd and 3rd lines to: double dValue = atof( value ); Glad I could help you out, I've had to overcome this hurdle many a time post-processing text input. Search Strategy: finding my old Deitel & Deitel book and dusting it off Additional Links: Online atof resource: http://www.dinkumware.com/htm_cl/stdlib.html#atof Thank you for the opportunity to answer your question, if you require more information, please clarify the question, or if you find this answer satisfactory, please feel free to rate it. Thank you! skermit-ga |
eksolutions-ga
rated this answer:
Thanks, you saved my life. I'm not very familiar with C++ and I was working on an OpenGL program. This simple function solved all my input problems... |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |