| | |
convert char* to double
![]() |
•
•
Join Date: Aug 2005
Posts: 188
Reputation:
Solved Threads: 3
hey, how would i go about converting a char* character array to a double.
I would like to create a function that takes a char array as a parameter such as "1234.1" and then return that as a double value 1234.1.
Is there a function that would allow me to do this or would i have to go about programming it myself?
Thanks.
I would like to create a function that takes a char array as a parameter such as "1234.1" and then return that as a double value 1234.1.
Is there a function that would allow me to do this or would i have to go about programming it myself?
Thanks.
>hey, how would i go about converting a char* character array to a double.
Provided the array is actually a string with a terminating '\0' character at the end, you can use strtod. Or, since this is C++, stringstreams make the conversion intuitive if you're used to cin and cout:
Provided the array is actually a string with a terminating '\0' character at the end, you can use strtod. Or, since this is C++, stringstreams make the conversion intuitive if you're used to cin and cout:
C++ Syntax (Toggle Plain Text)
#include <sstream> double to_double ( const char *p ) { std::stringstream ss ( p ); double result = 0; ss>> result; return result; }
Last edited by Narue; Jun 12th, 2007 at 12:32 pm.
I'm here to prove you wrong.
![]() |
Similar Threads
- How to LPCTSTR Convert to char * (C++)
- how to convert char to integer??? (C++)
- convert from 'ref double[]' to 'ref object' (C#)
- warning C4244: 'argument' : conversion from 'double' to 'char', possible loss of data (C)
Other Threads in the C++ Forum
- Previous Thread: Where to get good C++ GUI tutorials?
- Next Thread: How can I access these arrays without ifs
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes code coding compaitibility compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error factorial file floatingpoint forms fstream function functions game givemetehcodez graph guessing gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix maze memory multiple net news node oop output payment pointer practice problem program programming project projectassignmenthelp protection python random rank read recursion reference rpg skills string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






