开发者

C++ 64-bit std::ostream support

I am about to make the transition from using开发者_运维知识库 standard FILE pointers from some older code to using C++ streams but I need to have LARGEFILE seeking support (the compiler flags that activate this support are: -D_FILE_OFFSET_BITS=64 et al) which I am able to obtain by using the off64_t datatype.

My original question was answered regarding this subject matter and the C API, and now I am hoping to be able to transition towards using C++ streams.

Do the same flags trigger seeking ability on file streams in C++?


So I performed a quick test on a 16GB file and it seems to have worked. Here is the code that I used.

// 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";      
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜