How to convert string to double
-
wrote on 17 Jun 2013, 21:52 last edited by
std::string to double
i tried stof but it didn't work
i kept getting errors
it didn't recognize it -
wrote on 17 Jun 2013, 23:10 last edited by
Hi karim24.
Did you try using "QString::toDouble()":http://qt-project.org/doc/qt-4.8/qstring.html#toDouble
Regards -
wrote on 17 Jun 2013, 23:18 last edited by
What does this have to do with Qt?
One of quite a few options:
@
#include <string>
#include <cstdlib>std::string test("0.6");
double value = ::atof(test.c_str());
@ -
wrote on 17 Jun 2013, 23:20 last edited by
It is recommended to use QString for Qt projects but if you insists on using std::string you can easily find solution in similar topics:
- "C++ string to double conversion":http://stackoverflow.com/questions/4754011/c-string-to-double-conversion
- "How can I convert string to double in C++?":http://stackoverflow.com/questions/392981/how-can-i-convert-string-to-double-in-c
- "std::string to float or double":http://stackoverflow.com/questions/1012571/stdstring-to-float-or-double
-
wrote on 18 Jun 2013, 05:19 last edited by
This is a Qt forum, neither std::string nor stof() is part of Qt, and no other part of your question implicates Qt in any way. Hence my question.
You are probably getting errors, that you don't specify, because std::stof() is part of C++11 and your compiler, which you also did not specify, is defaulting to an earlier C++ standard. That's only a guess though.
-
wrote on 18 Jun 2013, 05:20 last edited by
The difference has to do with the compiler and libraries you use (VC vs MinGw), not with the fact that you use Qt or Qt Creator.
1/7