问题描述
我不知道是否可以使用预定义的读取缓冲区大小来缓冲读取大型文本文件(例如,std :: getline或fgets),或者必须使用特殊的bytewise函数?
I wonder if reading a large text file line by line (e.g., std::getline or fgets) can be buffered with predefined read buffer size, or one must use special bytewise functions?
我的意思是使用I / O操作数优化(例如,一次从HDD读取32 MB)来读取非常大的文件。当然我可以手工制作缓冲阅读,但我认为标准的文件流有这种可能性。
I mean reading very large files with I/O operations number optimization (e.g., reading 32 MB from the HDD at a time). Of course I can handcraft buffered reading, but I thought standard file streams had that possibility.
推荐答案
也不是特殊的逐字节功能。相反,以下应该做你的工作:
Neither line-by-line, nor special byte-wise functions. Instead, the following should do your job:
std::ifstream file("input.txt");
std::istream_iterator<char> begin(file), end;
std::vector<char> buffer(begin, end); //reading the file is done here!
//use buffer. it contains the content of the file!
完成后, buffer
包含文件的内容。
And you're done, as buffer
contains the content of the file.
这篇关于C ++缓冲文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!