Reading files larger than 4GB using c++ stl(使用 c++ stl 读取大于 4GB 的文件)
问题描述
几周前,我使用 std::ifstream 读取一些文件,但打开时立即失败,因为文件大于 4GB.当时我找不到合适的答案来解释为什么它被限制为 32 位文件大小,所以我使用原生 OS API 编写了自己的 API.
A few weeks back I was using std::ifstream to read in some files and it was failing immediately on open because the file was larger than 4GB. At the time I couldnt find a decent answer as to why it was limited to 32 bit files sizes, so I wrote my own using native OS API.
那么,我的问题是:有没有办法使用 std::ifstream/std::ostream(IE:标准 C++)处理大于 4GB 的文件
So, my question then: Is there a way to handle files greater than 4GB in size using std::ifstream/std::ostream (IE: standard c++)
使用来自 VC 9 编译器 (Visual Studio 2008) 的 STL 实现.当然必须有标准的方法来支持大于 4GB 的文件大小.
Using the STL implementation from the VC 9 compiler (Visual Studio 2008). Surely there has to be standard way to support file sizes larger than 4GB.
推荐答案
显然这取决于库如何实现 off_t
.
Apparently it depends on how off_t
is implemented by the library.
#include <streambuf>
__int64_t temp=std::numeric_limits<std::streamsize>::max();
为您提供当前的最大值.
gives you what the current max is.
STLport 支持更大的文件.
这篇关于使用 c++ stl 读取大于 4GB 的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 c++ stl 读取大于 4GB 的文件


基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09