Question
Please complete the below code as below requirements: Write the code that will save the first and last line of the text file so that
Please complete the below code as below requirements:
Write the code that will save the first and last line of the text file so that the cout statement at the end displays them out. The program should disregard any other line in the file, but it should print the first line, followed by "...yada, yada, yada... ", followed by the last line. When there are fewer than 2 lines (therefore not having a unique "last" line) in the file, it should print "The End." in place of a last line.
Code:
#include | |
#include | |
#include | |
using namespace std; | |
int main() | |
{ | |
ifstream file; | |
string filename; | |
string line; | |
string first; | |
string last; | |
bool success; | |
do | |
{ | |
cout<<"What file do you want paraphrased? "; | |
cin>>filename; | |
cin.ignore(); | |
file.open(filename); | |
success = file.is_open(); | |
if( success == false ) | |
{ | |
cout<<"Cannot open "< | |
} | |
}while( success == false ); | |
//Do stuff here that will get the first | |
//and last line of the text file | |
cout< | |
file.close(); | |
return 0; | |
} |
the text file as below:
hi dear,
iam
your work
I wish you
thanks
john
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started