| | |
convert char* to double
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
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 c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






