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. Error in Converting Qstring to std::string
Forum Update on Monday, May 27th 2025

Error in Converting Qstring to std::string

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.4k Views
  • 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 Offline
    R Offline
    Raminlich
    wrote on 9 Aug 2014, 10:31 last edited by
    #1

    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
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 9 Aug 2014, 12:01 last edited by
      #2

      [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
      0
      • R Offline
        R Offline
        Raminlich
        wrote on 9 Aug 2014, 13:11 last edited by
        #3

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

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JKSH
          Moderators
          wrote on 9 Aug 2014, 16:55 last edited by
          #4

          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
          0

          1/4

          9 Aug 2014, 10:31

          • Login

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