简单的程序,求指点为什么这里明明读到了文件结束之后还会多一次循环?
const char * file = "test.dat"; const char * fileout = "testout.dat"; ifstream fin; fin.open(file, ios_base::in |ios_base::binary); ofstream fout; streamoff i,j; if (fin.is_open()) { long n=0; char size[4]; while (! fin.eof() ) { fin.seekg(12, ios::cur); fin.read(size,4); n=*((long *)size); n=htonl (n); char *Buf=new char[n]; fin.read(Buf,n); fout.open(fileout,ios_base::out|ios_base::ate); j=fout.tellp(); fout.write(Buf,n); delete Buf; } } fin.close(); fout.close();