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
Get step-by-step solutions from verified subject matter experts
