Question: Please code in c++ Write a program that opens a file for reading and writing, and replaces each line with its reverse. For example, if

Please code in c++

Write a program that opens a file for reading and writing, and replaces each line with its reverse. For example, if you run

reverse hello.cpp then the contents of hello.cpp is changed to

 >maertsoi 
 ;"n\!dlrow, olleH"  

Of course, if you run reverse twice on the same file, then the original file is dis- played.

Please code in c++ Write a program that opens a file for

Note, when reaching the end-of-file, the stream will not write into file. Thus, to re-write the line that was read last, which sets EOF to true, you need to clear the flag by calling fstream::clear() Sample input-output: test.txt-Notepad File Edit Format View Help Hello World Hello Again Before Hello World Again! test.txt- Notepad File Edit Format View Help dlrow o1leH niagA ol1eH niaqA dlrow olleH After CWindows system321cmd.exe Enter the name of the file: test.txt Oriyinadidle test.txt content Hello World ello Again Hello World Again! Reversed file test.txt content: iagA olleH Press any key to continue . . niagA dlroW olleH Output CWindows system32cmd.exe Enter the name of the file:sonefile.txt Error opening file sonef Press any key to continue - ile.txt! If the file does not exist output

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!