Question: Using C++ corrdct and modify the code below. Currently the program will read the contents of a file and display each line in the file

Using C++ corrdct and modify the code below. Currently the program will read the contents of a file and display each line in the file to the screen. It will also display the line number followed by a colon. You will need to change the program so that it only display 24 lines from the file and waits for the user to press the enter key to continue. Do not use the system(pause) statement.

#include  #include  #include  #include  using namespace std; int main() { ifstream file; // File stream object string name; // To hold the file name string inputLine; // To hold a line of input int lines = 0; // Line counter int lineNum = 1; // Line number to display // Get the file name. cout << "Enter the file name: "; getline(cin, name); // Open the file. file.open(name); // Test for errors. if (!file) { // There was an error so display an error // message and end the program. cout << "Error opening " << name << endl; } else { // Read the contents of the file and display // each line with a line number. while (!file.eof()) { // Get a line from the file. getline(file, inputLine, ' '); // Display the line. cout << setw(3) << right << lineNum << ":" << inputLine << endl; // Update the line display counter for the // next line. lineNum++; // Update the total line counter. lines++; } // Close the file. file.close(); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!