Write a C++ program that displays the contents of a file in curses mode. If the
ID: 3854637 • Letter: W
Question
Write a C++ program that displays the contents of a file in curses mode. If the contents of the file are too big to fit on the screen, then your program needs to allow the user to scroll through the output using the up and down arrow keys.
Running program
Assuming your executable is called program1, you should be able to run your program as follows to open and display the contents of a file called filename.txt
$ ./program1 filename.txt
For this program, you will need to use the following prototype for main:
int main(const int argc, const char * argv []);
Explanation / Answer
#include <fstream>
#include <iostream>
using namespace std;
int main ( int argc, char *argv[] )
{
//argv[1] is filename
ifstream the_file ( argv[1] );
char x;
// the_file.get ( x ) returns false if EOF
while ( the_file.get ( x ) )
cout<< x;
// the_file is closed implicitly here
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.