阅读量:109
在 C++ 中,可以使用 atof 函数将字符串转换为浮点数
#include
#include
#include
int main() {
const char* str = "3.14";
double num = atof(str);
std::cout << "The float value is: " << num class="hljs-keyword">return 0;
}
在这个示例中,我们定义了一个包含浮点数的字符串 str,然后使用 atof 函数将其转换为 double 类型的浮点数 num。最后,我们输出转换后的浮点数。