C
chat
Hi,
I write program for writing and reading text file like this
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream outfile("test.txt");
for(int i=0;i<5;i++) outfile<<i<<endl;
outfile.close();
ifstream infile("test.txt");
int a;
while(infile) {
infile>>a;
cout<<a<<endl;
}
infile.close(); return 0;
}
The result is this
0
1
2
3
4
4
Can anybody tell me what is the mistake in my program. It should show 0
1 2 3 4 (only one 4).
Why does it show digit 4 two times? (this code was compile with vc++ 6)
Thank you in advance.
chat watchara
I write program for writing and reading text file like this
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream outfile("test.txt");
for(int i=0;i<5;i++) outfile<<i<<endl;
outfile.close();
ifstream infile("test.txt");
int a;
while(infile) {
infile>>a;
cout<<a<<endl;
}
infile.close(); return 0;
}
The result is this
0
1
2
3
4
4
Can anybody tell me what is the mistake in my program. It should show 0
1 2 3 4 (only one 4).
Why does it show digit 4 two times? (this code was compile with vc++ 6)
Thank you in advance.
chat watchara