Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Error in Converting Qstring to std::string

    General and Desktop
    2
    4
    2099
    Loading More Posts
    • 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.
    • R
      Raminlich last edited by

      hi all and this is my code
      @{

          QString names;
          ofstream mys("e:/mystock.txt");
          mys.open("e:/mystock");
         names.toStdString();
          mys<<names;
          mys.close();
      

      }
      @
      when i change "names" variable to string there is no error
      but when i change it to qstring and then i want to change it to std string this error will come:

      no match for 'operator<<' (operand types are 'std::ofstream {aka std::basic_ofstream<char>}' and 'QString')
      mys<<names;
      ^

      Thanks

      1 Reply Last reply Reply Quote 0
      • JKSH
        JKSH Moderators last edited by

        [quote]
        @
        names.toStdString();
        @
        [/quote]You need to use the return value of toStdString(). The function returns a copy of your data as a std::string, but it doesn't modify names. names is still a QString.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply Reply Quote 0
        • R
          Raminlich last edited by

          im very noob can you tell me how :| ?
          and thanks for your reply

          1 Reply Last reply Reply Quote 0
          • JKSH
            JKSH Moderators last edited by

            You're welcome :)

            @
            mys << names.toStdString();
            @

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply Reply Quote 0
            • First post
              Last post