使用ifstream查找大文件

时间:2012-07-12 09:22:16

标签: c++ file-io fstream

我正在使用必须在大文件(~1TB)中搜索的ifstream在C ++中实现一个程序。但是,读取2GB后失败。有没有办法获得文件位置,即使对于大文件?我编译为32位Windows机器。

std::ifstream f;
f.open( filename.c_str(), std::ifstream::in | std::ifstream::binary );
while(true) {
    std::cout << (uint64_t)(f.tellg()) << std::endl;
    //read data
}

1 个答案:

答案 0 :(得分:1)

由于您在32位平台上进行编译,因此如果使用fstream,则将获得32位访问权限。要访问大型文件,您需要使用平台相关的解决方案: