how to convert string into float in cppp code example
Example 1: how to change a string to an float in c++
#include <iostream>
#include <string>
int main() {
std::string str = "123.4567";
float num_float = std::stof(str);
double num_double = std::stod(str);
std:: cout<< "num_float = " << num_float << std::endl;
std:: cout<< "num_double = " << num_double << std::endl;
return 0;
}
Example 2: c++ std string to float
std::string num = "0.6";
double temp = ::atof(num.c_str());
std::cout << temp << std::endl;