【问题标题】:C++ 64-bit std::ostream supportC++ 64 位 std::ostream 支持
【发布时间】:2009-11-17 15:11:08
【问题描述】:
我即将从使用标准 FILE 指针从一些旧代码过渡到使用 C++ 流,但我需要 LARGEFILE 寻求支持(激活此支持的编译器标志是:-D_FILE_OFFSET_BITS=64 em> 等),我可以通过使用 off64_t 数据类型获得。
我的 original question was answered 关于这个主题和 C API,现在我希望能够过渡到使用 C++ 流。
相同的标志是否会触发 C++ 中文件流的搜索能力?
【问题讨论】:
标签:
c++
linux
64-bit
large-files
【解决方案1】:
所以我对一个 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";
}