1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > c语言 读取 文件大小 c – ifstream :: ifstream可以读取的最大文件大小是多少

c语言 读取 文件大小 c – ifstream :: ifstream可以读取的最大文件大小是多少

时间:2022-07-28 19:36:51

相关推荐

c语言 读取 文件大小 c – ifstream :: ifstream可以读取的最大文件大小是多少

我尝试使用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无法读取大文件,那么使用哪个好的流阅读器?

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。