C++ using microsoft visual studio express #include <iostream> #include <fstream>
ID: 669164 • Letter: C
Question
C++ using microsoft visual studio express
#include <iostream>
#include <fstream>
File Display Program.
Write a program that asks the user for the name of a file.
The program should display the content 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 the 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.
Include text file that will be inputed.
Explanation / Answer
#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");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.