// Mr. Minich // CMPSC 101 // Ch. 5 Demo Program #2
// January 30, 2000
// Purpose - to demonstrate opening a file for input and reading several pieces of data from a file
#include
#include <fstream>
using namespace std;
int main()
{
int num1 = 0; // first number read from the file
int num2 = 0; // second number read from the file
int num3 = 0; // third number read from the file
int sum = 0; // sum of the numbers read from the file
ifstream infile("myfile.txt");
infile >> num1;
infile >> num2;
infile >> num3;
sum = num1 + num2 + num3;
cout << "The first number is " <<
num1 << endl;
cout << "The first number is " <<
num2 << endl;
cout << "The first number is " <<
num3 << endl;
cout << "The sum is " << sum <<
endl;
infile.close();
return 0;
}// end of main