Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. c++ reading a large text file with fstream

c++ reading a large text file with fstream

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++ios
6 Posts 3 Posters 0 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.
  • N Offline
    N Offline
    nuttynibbles
    wrote on last edited by
    #1

    hi, im reading a large text file using fstream. below is my code: char logfile[10] = "log.txt"; char data[100]; fstream open_logviewer(logfile, ios::in); while(!open_logviewer.eof()){ open_logviewer.getline(data,100); cout << data << endl; } open_logviewer.close(); because the file has so many lines of data, when the program is executed, it will run through the data quickly to the end of line. this makes it hard for the user to read the data. how can i give user an option to probably press enter to view let say next 10 lines?

    T 1 Reply Last reply
    0
    • N nuttynibbles

      hi, im reading a large text file using fstream. below is my code: char logfile[10] = "log.txt"; char data[100]; fstream open_logviewer(logfile, ios::in); while(!open_logviewer.eof()){ open_logviewer.getline(data,100); cout << data << endl; } open_logviewer.close(); because the file has so many lines of data, when the program is executed, it will run through the data quickly to the end of line. this makes it hard for the user to read the data. how can i give user an option to probably press enter to view let say next 10 lines?

      T Offline
      T Offline
      T2102
      wrote on last edited by
      #2

      require user input using C++'s cin or C's scanf

      N 1 Reply Last reply
      0
      • T T2102

        require user input using C++'s cin or C's scanf

        N Offline
        N Offline
        nuttynibbles
        wrote on last edited by
        #3

        hi, erm what you're referring is read user input and print the particular line? if it is, i'm actually looking to print the whole chunk but allowing user to able to read every 10 lines per screen, after which, they press tab or enter to continue next 10 lines.

        N 1 Reply Last reply
        0
        • N nuttynibbles

          hi, erm what you're referring is read user input and print the particular line? if it is, i'm actually looking to print the whole chunk but allowing user to able to read every 10 lines per screen, after which, they press tab or enter to continue next 10 lines.

          N Offline
          N Offline
          nuttynibbles
          wrote on last edited by
          #4

          hmm i got it. its pretty simple acutally. i just simply find the difference between the counter and the prev 50 page. it looks like this: char logfile[10] = "log.txt"; char data[100]; fstream open_logviewer(logfile, ios::in); int counter = 1; int prev = 0; while(!open_logviewer.eof()){ open_logviewer.getline(data,100); cout << data << endl; if((counter - prev) == 50){ prev = counter; system("pause"); } counter++; } open_logviewer.close();

          L 1 Reply Last reply
          0
          • N nuttynibbles

            hmm i got it. its pretty simple acutally. i just simply find the difference between the counter and the prev 50 page. it looks like this: char logfile[10] = "log.txt"; char data[100]; fstream open_logviewer(logfile, ios::in); int counter = 1; int prev = 0; while(!open_logviewer.eof()){ open_logviewer.getline(data,100); cout << data << endl; if((counter - prev) == 50){ prev = counter; system("pause"); } counter++; } open_logviewer.close();

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            nuttynibbles wrote:

            if((counter - prev) == 50){

            What is the point of prev? A simple counter from 1 to 50 is all that's needed, resetting to 1 every time it hits 50. Something like:

            if(counter++ == 50)
            {
            system("pause");
            counter = 1;
            }

            N 1 Reply Last reply
            0
            • L Lost User

              nuttynibbles wrote:

              if((counter - prev) == 50){

              What is the point of prev? A simple counter from 1 to 50 is all that's needed, resetting to 1 every time it hits 50. Something like:

              if(counter++ == 50)
              {
              system("pause");
              counter = 1;
              }

              N Offline
              N Offline
              nuttynibbles
              wrote on last edited by
              #6

              this idea also works. thks :-D

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups