So I was going through my textbook and doing some of the fstream examples. I got through some of them except the ones where I am trying to read from a file. In my previous program I entered the following numbers 50, 40, 30, 20 to be read in this program. When I run this program I get " -858993460 -858993460 -858993460 -858993460. Their sum is 858993456." What exactly am I doing wrong?
int value1, value2, value3, value4, sum;
//Open the file.
//Read the four numbers from the file.
inFile >> value1;
inFile >> value2;
inFile >> value3;
inFile >> value4;
//Close the file.
//Calculate the sum of the numbers.
sum = value1 + value2 + value3 + value4;
//Display the four numbers.
cout << "Here are the numbers: \n"
<< value1 << " " << value2
<< " " << value3 << " " << value4
// Display the sum of the numbers.
cout << "Their sum is: " << sum << endl;