xxxxxxxxxx
#include <iostream>
#include <string>
#include <sstream>
int main() {
std::string str = "3.14"; // Example string
float num;
// Using stringstream to convert string to float
std::stringstream ss(str);
ss >> num;
// Check if the conversion was successful
if (!ss.fail()) {
std::cout << "Float value: " << num << std::endl;
} else {
std::cout << "Invalid input" << std::endl;
}
return 0;
}
xxxxxxxxxx
std::string num = "0.6";
double temp = ::atof(num.c_str());
std::cout << temp << std::endl;
// Output: 0.6