My goal is to convert numeric strings to doubles, using always period '.' as the decimal point, regardless of what setlocale() calls other threads might have been calling at the same time. The strtod() function would work nicely except it is affected by locale settings. I came up with the following (error checking and endptr stuff left out from here):
#include <string.h> #include <sstream> #include <locale> double strtod_dot(const char* nptr) { size_t n = strspn(nptr, "0123456789.eE+-"); std::istringstream is(std::string(nptr, n)); is.imbue(std::locale("C")); double f; is >> f; return f; } This works, but it is about 5 times slower than strtod() (yes, measured it) and makes a lot of useless work, whereas the operation should actually be simpler and faster than strtod(). Any suggestions what could I do better? TIA Paavo _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus