Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ iostream和大文件支持_C++_Stl_Iostream_Large Files_Large File Support - Fatal编程技术网

C++ iostream和大文件支持

C++ iostream和大文件支持,c++,stl,iostream,large-files,large-file-support,C++,Stl,Iostream,Large Files,Large File Support,我正试图找到一个明确的答案,但无法找到,所以我希望有人知道 我在Linux(32位OS)上使用GCC 4。x开发C++应用程序。此应用程序需要能够读取大小大于2GB的文件 我真的很想使用iostream stuff与文件指针,但是我找不到大文件定义(_LARGEFILE_SOURCE,_LARGEFILE64_SOURCE,_FILE_OFFSET_BITS=64)是否对iostream头有任何影响 我正在32位系统上编译。任何指针都会有帮助。这已经在编译libstdc++时为您决定,通常取决于

我正试图找到一个明确的答案,但无法找到,所以我希望有人知道

我在Linux(32位OS)上使用GCC 4。x开发C++应用程序。此应用程序需要能够读取大小大于2GB的文件

我真的很想使用iostream stuff与文件指针,但是我找不到大文件定义(_LARGEFILE_SOURCE,_LARGEFILE64_SOURCE,_FILE_OFFSET_BITS=64)是否对iostream头有任何影响


我正在32位系统上编译。任何指针都会有帮助。

这已经在编译
libstdc++
时为您决定,通常取决于
\u GLIBCXX\u USE\u LFS
是否在
c++config.h
中定义

如果有疑问,请通过
readelf-r
(或通过
strings
)传递您的可执行文件(或
libstdc++.so
,如果动态链接到它),并查看您的二进制文件是否链接到
fopen
/fseek/etc或
fopen64
/fseek64/etc

更新


只要您不需要/不尝试
fseek
ftell
(您只是从流中读取或写入),就不必担心2GB的限制。

如果您使用的是GCC,您可以利用名为u gnu cxx::stdio_filebuf的GCC扩展,它将IOStream绑定到标准的C文件描述符

您需要定义以下两件事:

_大文件源

_文件\u偏移量\u位=64

例如:

#include <cstdio>
#include <fstream>
#include <ext/stdio_filebuf.h>

int main()
{
  std::ofstream outstream;
  FILE* outfile;

  outfile = fopen("bigfile", "w");

  __gnu_cxx::stdio_filebuf<char> fdbuf(outfile, std::ios::out |
                                       std::ios::binary);
  outstream.std::ios::rdbuf(&fdbuf);

  for(double i = 0; i <= 786432000000.0; i++) {
    outstream << "some data";

  fclose(outfile);
  return 0;
#包括
#包括
#包括
int main()
{
std::流外扩;
文件*输出文件;
outfile=fopen(“大文件”,“w”);
__gnu_cxx::stdio_filebuf fdbuf(outfile,std::ios::out|
std::ios::binary);
outstream.std::ios::rdbuf(&fdbuf);

对于(i i=0;i)这并不能真正解决任何问题。为了能够调用fTele/fSek,需要64位偏移支持;因为使用STDIOYSycCyFielBuf,但是依赖于已经定义了必须搜索/读取位置的“SydibCxxx”UsIfLFS,但我确认了我的C++ LIBS有LFS支持,因此我可以使用FStand的“寻呼”呼叫。谢谢