Seeking in large files with ifstream

∥☆過路亽.° 提交于 2019-12-09 17:31:58

问题


I'm implementing a program in C++ using ifstream that must seek in large files (~1TB). However, this fails after reading 2GB. Is there a way to get file positions, even for large files? I compile for a 32-bit windows machine.

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:


Since you are compiling on a 32-bit platform, if you use fstream, you are going to get 32-bits access. To access large files, you need to use a platform dependent solution :

  • for windows, use _lseeki64()
  • for linux, use lseek64()


来源:https://stackoverflow.com/questions/11448713/seeking-in-large-files-with-ifstream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!