在 C++ 中处理大于 2 GB 的文件与STL

发布于 2024-10-07 02:25:55 字数 815 浏览 0 评论 0原文

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

当计算文件的大小时,我只是将 static_castpos_type 转换为 int64_t ,它似乎工作得很好。

seekg 怎么样?向其传递 int64_t 是否安全?

有没有办法让 pos_type off_type 成为 int64_t也许使用 traits

我想消除丑陋的强制转换并找到一种符合C++的方法标准。

更新:另请参阅

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).

When computing the size of the file I just static_cast the pos_type to an int64_t and it seems to work fine.

How about seekg? Is it safe to pass an int64_t to it?

Is there a way to make pos_type and off_type to be an int64_t, perhaps using traits?

I would like to eliminate the hideous cast and find a way that is in accordance with the C++ standard.

Update: see also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠意 2024-10-14 02:25:55

并非所有编译器都具有支持大文件的 STL 实现。

例如,以下程序:

#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 具有跨平台大文件支持。

Not all compilers have STL implementations with large file support.

For example, the following program:

#include <fstream>
#include <iostream>
#include <limits>

int main()
{
    using namespace std;

    cout << numeric_limits<streamoff>::max() << endl;
}

results in:

  • VS2005 - 2147483647
  • VS2008 - 2147483647
  • VS2010 - 9223372036854775807
  • MinGW GCC 4.4.0 - 9223372036854775807

On the other hand STLPort has cross platform large file support.

葬心 2024-10-14 02:25:55

您可能应该使用 std::fpos_t typedef。

You should probably use std::fpos_t typedef.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文