#include <iostream>
using namespace std;
int main() {
ifstream infile("input-file");
ofstream outfile("output-file");
if (infile.good() == false || outfile.good() == false) {
cout << "Unable to open one of the files." << endl;
exit (1);
}
while (true) {
getline(infile, line);
if (infile.eof()) break;
outfile << line << endl;
}
}
Checkpoint15.4.1.
Create a code block that sends output to a file. First, make sure that both the input file and the output file are able to be opened.
The code from the previous problem checks whether the files open or not. It doesnβt specify which one, if any, doesnβt open. How could you specify which file does not open?
Create two "if" statements, one that check whether in_file.good() is false, and another that checks whether out_file.good() is false, instead of putting them together in one "if" statement.