Important: Please read the Qt Code of Conduct -

Accessing text file contents

  • Hi,
    I am reading a text file by using the following code

    QFile inputFile("cotdr.txt");;
    QTextStream in(&inputFile);
    QString line = in.readAll();

    the text file contains the numbers like

    now I want to compare 6789 & 4567 and keep the maximum number(6789) and compare the kept number(6789) with 3467 and return the maximum number of each row
    finally I have to get an output file with maximum numbers 6789,7890,4567,7890,9845 also viceversa

    could some one please suggest me how could I do that?
    an example code helps me a lot using c++
    please hope someone knows about how to do that, i am eager to see the reply
    thanks heaps

  • @ while (!file.atEnd()) {
    QByteArray line = file.readLine();
    QList<QByteArray> numbers = line.split(',')
    for(QString numstr:numbers)
    int num = numstr.toInt();

  • Thanks for your reply, but when i complied it says doesn't support for loop in cpp.

    alos.i have one more question is there any possibility that i can setup qbytearray line as a two dimensional array

    how can compare when i have line numbers indexed with rows in qlist
    i need to compare the columns

Log in to reply