使用 c++ stl 读取大于 4GB 的文件

2023-08-26C/C++开发问题
7

本文介绍了使用 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 的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6