iostream 和大文件支持
我试图找到一个明确的答案,但找不到,所以我希望有人知道。
我正在 Linux(32 位操作系统)上使用 GCC 4.x 开发 C++ 应用程序。 该应用程序需要能够读取文件> 大小为2GB。
我真的很想使用 iostream 的东西与 FILE 指针,但我找不到大文件 #defines (_LARGEFILE_SOURCE、_LARGEFILE64_SOURCE、_FILE_OFFSET_BITS=64) 是否对 iostream 标头有任何影响。
我正在32位系统上编译。 任何指示都会有帮助。
I'm trying to find a definitive answer and can't, so I'm hoping someone might know.
I'm developing a C++ app using GCC 4.x on Linux (32-bit OS). This app needs to be able to read files > 2GB in size.
I would really like to use iostream stuff vs. FILE pointers, but I can't find if the large file #defines (_LARGEFILE_SOURCE, _LARGEFILE64_SOURCE, _FILE_OFFSET_BITS=64) have any effect on the iostream headers.
I'm compiling on a 32-bit system. Any pointers would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这在编译
libstdc++
时已经为您决定,通常取决于_GLIBCXX_USE_LFS
是否在c++config.h
中定义。如果有疑问,请通过
readelf -r
(或通过strings
)传递您的可执行文件(或libstdc++.so
,如果动态链接到它)查看您的二进制文件/libstdc++
是否链接到fopen
/fseek
/etc。 或fopen64
/fseek64
/等。更新
只要您不需要/尝试
fseek
或ftell
(您只需从流中读取或写入。)This has already been decided for you when
libstdc++
was compiled, and normally depends on whether or not_GLIBCXX_USE_LFS
was defined inc++config.h
.If in doubt, pass your executable (or
libstdc++.so
, if linking against it dynamically) throughreadelf -r
(or throughstrings
) and see if your binary/libstdc++
linked againstfopen
/fseek
/etc. orfopen64
/fseek64
/etc.UPDATE
You don't have to worry about the 2GB limit as long as you don't need/attempt to
fseek
orftell
(you just read from or write to the stream.)如果您使用 GCC,则可以利用名为 __gnu_cxx::stdio_filebuf 的 GCC 扩展,它将 IOStream 与标准 C FILE 描述符联系起来。
您需要定义以下两件事:
例如:
}
If you are using GCC, you can take advantage of a GCC extension called __gnu_cxx::stdio_filebuf, which ties an IOStream to a standard C FILE descriptor.
You need to define the following two things:
For example:
}