vs c++ 将string转换为double

可以用atof()这个函数,但是这个函数的参数是char*类型的,因此需将string类型强制转换,方法为在函数的参数中写成 const_cast<const char *>(str.c_str())

string str = "1.26";
double d = atof(const_cast<const char *>(str.c_str()));

原文地址:https://www.cnblogs.com/qingsunny/p/3169773.html