How to read number from file(casting- the numbers has readen as string)- c++ qt
-
wrote on 6 Oct 2022, 05:58 last edited by RuWex 10 Jun 2022, 06:09
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:) -
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:)@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
-
@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
wrote on 6 Oct 2022, 08:40 last edited by JonB 10 Jun 2022, 08:42@jsulm
OoI, why did Qt6QString
feel the need to introducesliced()
when we have hadmid()
for years?
EDIT Oh,mid()
docs now sayIf you know that position and n cannot be out of bounds, use sliced() instead in new code, because it is faster.
1/3