Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to convert string to double
Forum Updated to NodeBB v4.3 + New Features

How to convert string to double

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 36.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    karim24
    wrote on 17 Jun 2013, 21:52 last edited by
    #1

    std::string to double
    i tried stof but it didn't work
    i kept getting errors
    it didn't recognize it

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SergioDanielG
      wrote on 17 Jun 2013, 23:10 last edited by
      #2

      Hi karim24.
      Did you try using "QString::toDouble()":http://qt-project.org/doc/qt-4.8/qstring.html#toDouble
      Regards

      www.ftatv.com.ar El foro argentino de la TV libre

      1 Reply Last reply
      1
      • C Offline
        C Offline
        ChrisW67
        wrote on 17 Jun 2013, 23:18 last edited by
        #3

        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());
        @

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on 17 Jun 2013, 23:20 last edited by
          #4

          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

          http://anavi.org/

          1 Reply Last reply
          1
          • K Offline
            K Offline
            karim24
            wrote on 17 Jun 2013, 23:32 last edited by
            #5

            @ChrisW67
            What does this have to do with Qt?
            because i used "stof" in most of my code
            when i was using visual c++ it worked fine
            but when i used it in qtcreator there were errors
            and now "atof" working just fine for me thanks

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on 18 Jun 2013, 05:19 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on 18 Jun 2013, 05:20 last edited by
                #7

                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 Reply Last reply
                0

                1/7

                17 Jun 2013, 21:52

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved