Is there a function in any of the standard libraries that does this, or do I have ot create my own?
Is there a function in any of the standard libraries that does this, or do I have ot create my own?
You mean take a null terminated array of characters that contains the textual representation of a floating point number and return said floating point number?
The function is atof() //(ascii to float)
It takes a pointer to the array of char and returns a double precision floating pooint value.
It is found in <cstdlib>.
strtod() would be better choice.
So... what's the second paramiter of strtod() supposed to be?
Did you look it up?Originally posted by Nippashish
So... what's the second paramiter of strtod() supposed to be?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
What am I saying! This is a C++ board, use a stringstream.
Although if you still want info on strtod() go here: http://www.opengroup.org/onlinepubs/...sh/strtod.html
An example of a stringstream converting a char * to a float:
What part of Nova Scotia do ye hail from?Code:#include <iostream> #include <sstream> using namespace std; int main () { float val; stringstream ss (stringstream::in | stringstream::out); ss << "1.2"; ss >> val; cout << val*2 << endl; return 0; }
Last edited by Eibro; 11-03-2002 at 08:34 PM.
Was thinking the same thing, Elbro.
Why are you using a nul terminated array of char anyway, nippa? Strings are almost always better.
I never really used strings before so it just never occured to me, I'm using them now though, and it's making my life a hell of a lot easier .
And I'm from the Bridgewater area.
Last edited by Nippashish; 11-03-2002 at 10:00 PM.