//-------------------------------------------------------------------- // // Example showing the use of an input file infile1.cpp // //-------------------------------------------------------------------- // Reads the first five integer values from the file values.dat and // displays their sum. #include // For cin and cout #include // For file input/output void main() { ifstream inFile("values.dat"); // Open input file values.dat int num, // Number read from file sum = 0; // Sum of numbers read in // Read in numbers and compute their sum. for ( int j = 0 ; j < 5 ; j++ ) { inFile >> num; cout << num << endl; sum += num; } // Output the sum. cout << "Sum = " << sum << endl << endl; // Close the input file stream. inFile.close(); }