I've got this weird behavior with std::atof in Ubuntu 18.0.4 with Qt Creator(4.10) as IDE / gcc 7.4.0 :
It parses strings as normal when i run in debug mode from QtCreator. But it floors when i run normally.
Example code with this behavior:
std::string exampleStr = "3.0303";
std::cout << "string value: " << exampleStr << std::endl;
std::cout << "double value - c_str(): " << std::atof(exampleStr.c_str()) << std::endl;
Output with normal run from IDE:
string value: 3.0303
double value - c_str(): 3
Output with running directly from executable:
string value: 3.0303
double value - c_str(): 3
Output with debug mode:
string value: 3.0303
double value - c_str(): 3.0303
I've tried both std::stof and std::strtof. Both same. Anybody knows the reason or work around of this bug?
Edit: I've workaround with this, but still wonder the reason of this behavior.
std::string exampleStr = "3.0303";
std::stringstream ss;
ss << exampleStr;
float val = 0;
ss >> val;
std::cout << "Float value: " << val << std::endl;