#include <fstream>
#include<iostream>
#include <iomanip>
#include <stdlib.h>
#include <conio.h>
using namespace std;
#define size 3
void main()
{
int arr[10],sum=0;
ifstream infile;
infile.open("input.txt", ios::in);
if (infile.fail()){
cerr<< "Input file cannot open ";
exit(-1);
}
while(!infile.eof()){
for(int i=0; i<10; i++)
{
infile >> arr[i];
cout <<setw(4)<< arr[i];
sum += arr[i];
}
infile.close();
cout << sum;
}
_getch();
}
The input file can be read,but it will be read twice.
can anyone help me to see what is the problem