Why does this stupid code read twice last number??? Tnx
#include <stdlib.h>
#include <iostream>
#include <fstream>
using namespace std;
int main ( )
{
int number;
ofstream testfile ( "test.txt" , ios::app);
cout<<"Insert a number, ctrl+z to end"<<endl;
while(cin>>number){
testfile<<number<<endl;
cout<<"Insert a number, ctrl + z to end"<<endl;
}
testfile.close();
cout<<"Reading number(s)from file..."<<endl;
ifstream testfile2 ("test.txt" , ios::in );
while(!testfile2.eof()){
testfile2>>number;
cout<<number<<endl;
}
system ("pause");
}