Parsowanie ciągu znaków do double jest osiągalne w C dzięki funkcji strtod. Jest to dość stara funkcja, obecna w standardzie C90 (z roku 1990).
Składnia to:
double strtod (const char* str, char** endptr);
Przykład:
char* pEnd; double d1; d1 = strtod ("3.14", &pEnd); cout << d1 <<endl;//3.14 d1 = strtod ("12,34", &pEnd); cout << d1 <<endl;//12 d1 = strtod ("-1.55211e-016", &pEnd); cout << d1 <<endl;//-1.55211e-16 d1 = strtod ("8.67548e-017", &pEnd); cout << d1 <<endl;//8.67548e-17 d1 = strtod ("8.67548e+1017", &pEnd); cout << d1 <<endl;//inf d1 = strtod ("abc", &pEnd); cout << d1 <<endl;//0 d1 = strtod ("", &pEnd); cout << d1 <<endl;//0 d1 = strtod (NULL, &pEnd); cout << d1 <<endl;//exit!