4
我有一个简单的C++程序,它逐行读取一个文件。一些行包含超过20000个字符。以下程序只能读取那些大行的4095个字符。我认为这是因为缓冲区大小的限制。阅读大篇幅的解决方案是什么?C++中getline的缓冲区大小限制
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream myfile ("new.fasta");
if (myfile.is_open())
{
while (getline (myfile,line))
{
cout << line.length() << '\n';
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
您的文本文件在打到换行符之前有超过20K个字符? – NathanOliver
@NathanOliver是的,有时超过30K也 –
如果在声明之后执行'line.reserve(20000);'会发生什么?这将有助于缩小如果它是'getline'或字符串增长的问题。 – NathanOliver