What do you mean it will not read twice? Also you don't need to give an ifstream the in flag , you only need that for fstreams since they can be in or out.
Also I believe you should have
1 2 3 4 5 6
while( !infile.eof() ) //or better to use good()
{
infile >> arr[i];
cout << setw(4) << arr[i];
sum += arr[i];
}
a) use cstdlib.
b) use int main
c) what do you mean read twice? like the file contains 5 ints and fills all 10? i feel like the problem is in your nested loops