Qt Forum

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

    Unsolved How to read number from file(casting- the numbers has readen as string)- c++ qt

    Tools
    c++ file string int casting
    3
    3
    123
    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
      RuWex last edited by RuWex

      Let's say I want to read this file:
      ///
      readLine25
      goToLine1
      ....
      ///
      now,
      How can I treat int as int? and the string as string?
      I want to get the number,
      for example in line 1 I want to get 25
      an important note.
      the string allways 8 chars- not less not more!
      thanks:)

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @RuWex last edited by

        @RuWex said in How to read number from file(casting- the numbers has readen as string)- c++ qt:

        How can I treat int as int?

        https://doc.qt.io/qt-6/qstring.html#toInt

        To get the number string simply use https://doc.qt.io/qt-6/qstring.html#sliced

        So, first call https://doc.qt.io/qt-6/qstring.html#sliced to get the part of the string which contains the int and then convert that string to int using https://doc.qt.io/qt-6/qstring.html#toInt

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        JonB 1 Reply Last reply Reply Quote 1
        • JonB
          JonB @jsulm last edited by JonB

          @jsulm
          OoI, why did Qt6 QString feel the need to introduce sliced() when we have had mid() for years?
          EDIT Oh, mid() docs now say

          If you know that position and n cannot be out of bounds, use sliced() instead in new code, because it is faster.

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