Use std::stod
for such operations if you have access to C++11.
Otherwise use std::f="https://forum.tuteehub.com/tag/string">stringstream
as in the following:
double f = 0.0;
std::f="https://forum.tuteehub.com/tag/string">stringstream ss;
std::f="https://forum.tuteehub.com/tag/string">string s = "213.1415";
ss << s;
ss >> f; //f now contains the converted f="https://forum.tuteehub.com/tag/string">string into a double
f="https://forum.tuteehub.com/tag/cout">cout << f;
manpreet
Best Answer
2 years ago
This question already has an answer here:
I want to convert string to float. I used the function std::atof, but when i have a string of zero this does not work because the return number of std::atof is 0 if it was succesful. Some of the strings are not numbers. There for, with this code i wrote:
This will not work for zero. What can I do so this will work for zero? Thanks.