//DISPLAY 6.2 File I/O with Checks on open //Reads three numbers from the file infile.dat, sums the numbers, //and writes the sum to the file outfile.dat. #include #include #include int main( ) { using namespace std; ifstream inStream; ofstream outStream; inStream.open("infile.dat"); if (inStream.fail( )) { cout << "Input file opening failed.\n"; exit(1); } outStream.open("outfile.dat"); if (outStream.fail( )) { cout << "Output file opening failed.\n"; exit(1); } int first, second, third; inStream >> first >> second >> third; outStream << "The sum of the first 3\n" << "numbers in infile.dat\n" << "is " << (first + second + third) << endl; inStream.close( ); outStream.close( ); return 0; }