// reads three numbers from the file infile.dat, sums the numbers, // and writes the sum to the file outfile.dat. // checks if file is opened successfully // Walt Savitch // 03/14/00 #include #include #include using std::ifstream; using std::ofstream; using std::endl; int main() { ifstream fin; ofstream fout; fin.open("infile.dat"); if (fin.fail()) { cout << "Input file opening failed.\n"; exit(1); } fout.open("outfile.dat"); if (fout.fail()) { cout << "Output file opening failed.\n"; exit(1); } int first, second, third; fin >> first >> second >> third; fout << "The sum of the first 3 numbers is " << first + second + third << endl; fin.close(); fout.close(); }