C++STL-检测二进制文件的末尾
C++ STL - detecting reaching end of binary file
可能重复:
为什么std::fstream会以这种方式设置EOF位?
你好
iam使用read(…)加载二进制文件,但是,eof()永远不会为真因此,我使用gcount()检查文件结尾,这显然是错误的
如何正确检测二进制文件的eof()?
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
}
我发现一篇文章正在讨论这个问题。
相关文章:
- 正在读取二进制文件(is_open)
- 在C++中将类(带有Vector成员)保存为二进制文件
- 如何从二进制文件中读取字符串
- 保存/加载大量短数组到二进制文件
- 从二进制文件中读取整数数组
- Android 在编译二进制文件时重建静态库
- 在 C++ 中将双精度变量写入二进制文件
- clang 的 libFuzzer 可以在同一二进制文件中测试超过 1 个 API 吗?
- C++:实际上不是从二进制文件中读取
- 如何从二进制文件中的给定符号中获取调用程序图
- 将内部带有矢量的结构保存/读取到二进制文件中
- 编译多个C++文件.调用二进制文件以运行代码
- 如何使用位字段将数据从二进制文件复制到结构中?
- 仅捕获异常就可以检测所有二进制文件在C 中读取错误是否足够
- 检测二进制文件数据的端性
- PIN - 获取正在检测的二进制文件的进程 ID
- 代码覆盖率错误(未检测二进制文件)
- 如何检测二进制文件已被完全消耗
- C++STL-检测二进制文件的末尾
- 检测二进制文件的GCC编译时标志