ifstream问题
#include<iostream>#include<fstream>
#include<cassert>
#include<cstdlib>
using namespace std ;
int main()
{
ofstream out ;
out.open("D:\\data.dat",ios_base::out);
assert(out);
int i ;
const int size = 10 ;
int data ;
for(i = 0 ; i<size ;i++)
{
data = rand() ;
out<<data<<"\t";
}
out<<endl;
out.close() ;
ifstream in("D:\\data.dat");
assert(in);
int cnt = 0 ;
while(!in.eof())
{
in>>data ;
cnt ++ ;
}
cout<<"cnt="<<cnt<<endl;
system("pause");
return 0 ;
}
为什么cnt是11?
而不是10!