Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Please modify the following code using getline(cin,strObj) with cout<<strObj<<endl; or getline(infile,strObj) with outfile<<strObj<<endl; 

 

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>


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;
}
Chapter 9 501
Exceptions and File Checking

 

 

thank you

 

 

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