我尝试使用ifstream读取3GB数据文件,它给我错误的文件大小,而当我读取600MB文件时,它给了我正确的结果.除了错误的文件大小,我也无法使用ifstream读取整个文件.
这是我使用的代码
std::wstring name;
name.assign(fileName.begin(), fileName.end());
__stat64 buf;
if (_wstat64(name.c_str(), &buf) != 0)
std::cout << -1; // error, could use errno to find out more
std::cout << " Windows file size : " << buf.st_size << std::endl;;
std::ifstream fs(fileName.c_str(), std::ifstream::in | std::ifstream::binary);
fs.seekg(0, std::ios_base::end);
std::cout << " ifstream file size: " << fs.tellg() << std::endl;
3GB文件的输出是
Windows file size : 3147046042
ifstream file size: -1147921254
而600 MB文件的输出是
Windows file size : 678761111
ifstream file size: 678761111
为了以防万一,我还测试了5GB文件和300 MB文件,
5GB文件的输出是
Windows file size : 5430386900
ifstream file size: 1135419604
300MB文件的输出是
Windows file size : 318763632
ifstream file size: 318763632
它看起来像是达到了一些限制.
我正在Windows机器上使用Visual Studio 测试代码,该机器具有足够的内存和磁盘空间.
我正在尝试阅读一些大文件.如果ifstream无法读取大文件,那么使用哪个好的流阅读器?