1. (Practice) Enter the data for the info.txt file in Figure 9.1 or download it from this book’s Web site. Then enter and execute Program 9.5 and verify that the backup file was written. 2. (Modify) Modify Program 9.5 to use a getline() function in place of the get() method currently in the program.   =============1 - 9.1========== #include #include #include // needed for exit() #include using namespace std; int main() { string fileOne = "info.txt"; // put the filename up front string fileTwo = "info.bak"; char ch; ifstream inFile; ofstream outfile; try //this block tries to open the input file { // open a basic input stream inFile.open(fileOne.c_str()); if (inFile.fail()) throw fileOne; } // end of outer try block catch (string in) // catch for outer try block { cout << "The input file " << in << " was not successfully opened." << endl << " No backup was made." << endl; exit(1); } try // this block tries to open the output file and { // perform all file processing outfile.open(fileTwo.c_str()); if (outfile.fail())throw fileTwo; while ((ch = inFile.get())!= EOF) outfile.put(ch); inFile.close(); outfile.close(); } catch (string out) // catch for inner try block { cout << "The backup file " << out << " was not successfully opened." << endl; exit(1); } cout << "A successful backup of " << fileOne << " named " << fileTwo << " was successfully made." << endl; return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

1. (Practice) Enter the data for the info.txt file in Figure 9.1 or download it from this book’s Web site. Then enter and execute Program 9.5 and verify that the backup file was written.


2. (Modify) Modify Program 9.5 to use a getline() function in place of the get()
method currently in the program.

 

=============1 - 9.1==========

#include <iostream>
#include <fstream>
#include <cstdlib> // needed for exit()
#include <string>
using namespace std;

int main()
{
string fileOne = "info.txt"; // put the filename up front
string fileTwo = "info.bak";
char ch;
ifstream inFile;
ofstream outfile;
try //this block tries to open the input file
{
// open a basic input stream
inFile.open(fileOne.c_str());
if (inFile.fail()) throw fileOne;
} // end of outer try block
catch (string in) // catch for outer try block
{
cout << "The input file " << in
<< " was not successfully opened." << endl
<< " No backup was made." << endl;
exit(1);
}
try // this block tries to open the output file and
{ // perform all file processing
outfile.open(fileTwo.c_str());
if (outfile.fail())throw fileTwo;
while ((ch = inFile.get())!= EOF)
outfile.put(ch);
inFile.close();
outfile.close();
}
catch (string out) // catch for inner try block
{
cout << "The backup file " << out
<< " was not successfully opened." << endl;
exit(1);
}
cout << "A successful backup of " << fileOne
<< " named " << fileTwo << " was successfully made." << endl;
return 0;
}

*info.txt Notepad
File Edit Format View Help
sample text 1
sample text 1
sample text 1
Transcribed Image Text:*info.txt Notepad File Edit Format View Help sample text 1 sample text 1 sample text 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY