How to read number from file(casting- the numbers has readen as string)- c++ qt
-
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
-
@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.