我将从使用旧文件的标准FILE指针过渡到使用C++流,但是我需要LARGEFILE寻找支持(激活该支持的编译器标志为:-D_FILE_OFFSET_BITS = 64等),我能够通过使用off64_t数据类型获得。

关于这个主题和C API的我的original question was answered,现在我希望能够过渡到使用C++流。

是否在C++中使用相同的标志触发对文件流的搜索能力?

最佳答案

因此,我对16GB的文件进行了快速测试,它似乎奏效了。这是我使用的代码。

// compiled with : g++ -o largefile -D_FILE_OFFSET_BITS=64 largefile.cpp
#include "iostream"
#include "fstream"

int
main (int argc, char * argv[]) {
        char line[4096];
        std::ifstream stream ("/home/jbellone/largefile.csv");

        // Seek forward to somewhere past 4GB
        stream.seekg (10294967296, std::ios_base::beg);

        stream.getline (line, 100);

        std::cout << stream.tellg() << " " << line << "\n";
}

10-08 14:49