Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Accessing text file contents
Qt 6.11 is out! See what's new in the release blog

Accessing text file contents

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    pushpa416
    wrote on last edited by
    #1

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

    QFile inputFile("cotdr.txt");
    inputFile.open(QIODevice::ReadOnly);
    QTextStream in(&inputFile);
    QString line = in.readAll();
    inputFile.close();

    the text file contains the numbers like
    6789,1234,4567,7890,9845
    4567,7890,1234,4523,6789
    3467,4304,2411,1111,2321

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chezgi
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pushpa416
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved