Unsolved How to read number from file(casting- the numbers has readen as string)- c++ qt
Let's say I want to read this file:
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!
jsulm Lifetime Qt Champion 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?
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
JonB last edited by JonB
OoI, why did Qt6
QStringfeel the need to introduce
sliced()when we have had
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.