Question: c++ my code : #include #include using namespace std; int main() { string filename; cout >filename; filename = filename + .txt; fstream file; file.open(filename.c_str()); if(file.is_open())
c++
my code :
#include
using namespace std;
int main() { string filename; cout >filename; filename = filename + ".txt"; fstream file; file.open(filename.c_str()); if(file.is_open()) { cout
Problem:

Write a program that prompts the user to enter an input file's name. Here is an example of the program's screen: What is the name of the input file? test Once the user has entered the name of the input file, add the extension (.txt) to get the full name: test.txt. Then the program opens the file and displays its contents to the screen, one line at a time. Finally, it closes the file and displays the number of lines in the input file as shown below: The input file named "test.txt" has 5 lines. If the user enter the wrong name for the input file, display the following error message: There was an error opening the input file: "test.txt" Output is nearly correct; but whitespace differs. See highlights below. Special character legend Input song_row What is the name of the input file? Row, row, row your boat, Gently down the stream. Your output Merrily, merrily, merrily, merrily, Life is but a dream. The input file named "song_row.txt" has 4 lines. Expected output What is the name of the input file? Row, row, row your boat, Gently down the stream. Merrily, merrily, merrily, merrily, Life is but a dream. The input file named "song_row.txt" has 4 lines
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
