Possible Duplicate:
Why does std::fstream set the EOF bit the way it does?
hello
iam loading a binary file using rea开发者_运维百科d(...), however, the eof() gets never true so i check for file end using gcount(), which obviosly is plain wrong
how to detect eof() of a binary file properly?
std::ifstream rf;
rf.open(fpath.c_str(), std::ios::in | std::ios::binary);
while(!rf.eof()) {
std::string objectName;
READ_STR_FROM_BINFILE(rf, objectName);
//macro code : {
// size_t len;
// ff.read(reinterpret_cast<char *>(&len), sizeof(len));
// std::vector<char> v(len);
// ff.read(&v[0], len);
// ss = std::string(v.begin(), v.end());
//}
if (rf.gcount() == 0) {
//if this happens, there is nothing more to read
//but the strange thing is, .eof() is not true at this point
break;
}
//loading some structures here
}
I've found an article discussing just that.
精彩评论