Isn't once we use open(..) function to open the ifstream file will automatically place the file pointer to the beginning?
Look at the line with question mark commented out, if this clear() function not exist there, the file cannot be readed out, it is definitely eof reported with the open function. why?
Code:
ifstream inF("file.dat", ios::in | ios::binary);
for (;;) {
inF.read((char *)&num, sizeof(int));
if (inF.gcount() == 0)
break;
cout << num << endl;
}
inF.close();
ifstream inF("file.dat", ios::in | ios::binary);
inF.clear(); // ???
for (;;) {
inF.read((char *)&num, sizeof(int));
if (inF.gcount() == 0)
break;
cout << num << endl;
}
inF.close();
Look at the line with question mark commented out, if this clear() function not exist there, the file cannot be readed out, it is definitely eof reported with the open function. why?