Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道是否可以使用预定义的读取缓冲区大小来逐行读取大型文本文件(例如,std::getline 或 fgets),或者必须使用特殊的字节函数?
我的意思是通过 I/O 操作数优化读取非常大的文件(例如,一次从 HDD 读取 32 MB)。当然我可以手工缓冲读取,但我认为标准文件流有这种可能性。
既不是逐行的,也不是特殊的字节函数。相反,以下应该做你的工作:
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包含文件的内容。
buffer