c++ reading a large text file with fstream
-
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? -
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? -
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.
-
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.
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();
-
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();
-
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;
}this idea also works. thks :-D