使用STL在C ++中处理大于2 GB的文件 [英] Processing files larger than 2 GB in C++ with STL
问题描述
我正在执行二进制文件处理,并且在我的算法中,我想知道pos_type
和off_type
的实际类型,例如,在计算文件大小或寻求给定位置时(tellg
和seekg
).
I am doing binary file processing and in my algorithm I would like to know the actual type of pos_type
and off_type
, for example when computing the size of the file or seeking to a given position (tellg
and seekg
).
在计算文件大小时,我只是将static_cast
pos_type
更改为int64_t
,它似乎可以正常工作.
When computing the size of the file I just static_cast
the pos_type
to an int64_t
and it seems to work fine.
seekg
怎么样?将int64_t
传递给它是否安全?
How about seekg
? Is it safe to pass an int64_t
to it?
有没有办法使 pos_type
和 off_type
成为 int64_t
,可能使用 traits
?
我想消除丑陋的演员,找到一种符合C ++标准的方法.
I would like to eliminate the hideous cast and find a way that is in accordance with the C++ standard.
更新:另请参见
推荐答案
并非所有编译器都具有支持大文件的STL实现.
Not all compilers have STL implementations with large file support.
例如,以下程序:
#include <fstream>
#include <iostream>
#include <limits>
int main()
{
using namespace std;
cout << numeric_limits<streamoff>::max() << endl;
}
导致:
- VS2005-2147483647
- VS2008-2147483647
- VS2010-9223372036854775807
- MinGW GCC 4.4.0-9223372036854775807
另一方面, STLPort 具有跨平台大文件支持.
On the other hand STLPort has cross platform large file support.
这篇关于使用STL在C ++中处理大于2 GB的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!