This complicated function illustrates how to use strtod properly, It converts an string that looks like a floating point number (a double) into that number: #include #include using namespace std; // if you want spaces after the number to be acceptable (spaces // before the number always are, for some reason) you need this // larger version of the function double convert(string s, bool & ok) { char * x; double d = strtod(s.c_str(), & x); int i = 0; while (true) { char c = x[i]; if (c == '\0') break; if (c != ' ') { ok = false; return 0.0; } i += 1; } ok = true; return d; } // if you know there will not be spaces after the number, or you // want them to be considered incorrect, all you need is this double convert(string s, bool & ok) { char * x; double d = strtod(s.c_str(), & x); ok = * x == 0; return d; } The best thing is to just use convert exactly as it is. Here's an example use: { string s1 = " 3.251e-7 "; // spaces not needed, just demonstrating string s2 = "3.215e-7x"; // that they are allowed. bool ok; double d1 = convert(s1, ok); if (ok) // you will see "The value is 3.251e-07" cout << "The value is " << d1 << "\n"; else cout << s1 << " is not a valid number\n"; double d2 = convert(s2, ok); if (ok) // you will see "3.215e-7x is not a valid number" cout << "The value is " << d2 << "\n"; else cout << s2 << " is not a valid number\n"; } It is annoying because the function that does all the work is a C function, it has not been updated to C++. That is why it has some odd things in it. If you read about a "better" way, it isn't. The official C++ version called stod does not work properly.