使用STL在C ++中处理大于2 GB的文件 [英] Processing files larger than 2 GB in C++ with STL

查看:98
本文介绍了使用STL在C ++中处理大于2 GB的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行二进制文件处理,并且在我的算法中,我想知道pos_typeoff_type的实际类型,例如,在计算文件大小或寻求给定位置时(tellgseekg).

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.

更新:另请参见

iostream和大文件支持

推荐答案

并非所有编译器都具有支持大文件的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆