I am quite new at programing. I want to write a program that reads a textfile and then prints the content on the screen 25 rows at the time. I have read quite much about ifstream and ofstream. I wrote this program to count the lines in a file. And I was thinking that if I count the number of lines in a file I would be able to print the lines to the screen until there are no more lines in the file.

#include <iostream>
#include <fstream>
using namespace std;
int main()
  ifstream in; // Detta är en inström som kopplas till en fil.
  char rad[200]; // Buffer för en rad med tecken
  char filnamn[50]; // Filensnamn.
  int antalrader=0;  

  cout << "Ange filens namn ? ";

  // Öppnar filen med det namn som användaren angivit.  

  // Testar om det inte gick att öppna filen.
      cout << "Det gick ej att oppna filen " << filnamn << endl;
      return 0;

  // Så länge inte filslut hittats
  cout << "Filen " << filnamn << " innehåller " << antalrader << " rader" << endl;

  return 0;

Another idea was to put some kind of counter in a while-loop.

    std::string str;
    std::cout << str << std::flush;

The thing is that I am not that great learning from reading. Any help would great. It is one thing to know how to print a whole file to the screen but another to print some lines at the time.

I also wonder is I can use the manipulator noskipws to make sure all the spaces get copied.

Best Regards


Its ifstream not instream. And if you have read a lot about it you need to try to write the program yourself then post what you have done if you have problems.