I am trying to write a code that is giving me a great deal of problems.
The program challenge is as follows:
Write a program that asks the user for the name of a file. The program shold display the contents of the file on the screen. If the file's contents won't fit on a single screen, the program should display 24 lines of output at a time, and then pause. Each time the program pauses, it should wait for the user to strike a key before the next 24 lines are displayed.
NOTE: Using an editor, you should create a simple text file that can be used to test this program.
I have written some code and it sort of works, but my .txt file is not showing in the command window. Please help!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
cout << "Please enter the name of the file: ";
string fileName;
getline(cin, fileName);
ifstream file(fileName.c_str(), ios::in);
string line;
for (int count = 1; !file.eof(); ++count)
{
getline(file, line);
cout << line << endl;
if (count % 24 == 0) system("Pause");
}
system("Pause");
}