C ++中getline的缓冲区大小限制
buffer size limit for getline in C++
我有一个简单的 C++ 程序,它逐行读取文件。有些行包含超过 20000 个字符。下面的程序只能读取那些大行的 4095 个字符。我认为这是因为缓冲区大小限制。读取大行的解决方案是什么?
// 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;
}
尝试 sed ${n}p | wc
输入,其中 n
是有问题的行号。我的猜测是 wc 会报告它是 4095 个字符,或者在位置 4096 有一些特殊的东西。
根据标准,std::getline
没有缓冲区大小限制。
我有一个简单的 C++ 程序,它逐行读取文件。有些行包含超过 20000 个字符。下面的程序只能读取那些大行的 4095 个字符。我认为这是因为缓冲区大小限制。读取大行的解决方案是什么?
// 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;
}
尝试 sed ${n}p | wc
输入,其中 n
是有问题的行号。我的猜测是 wc 会报告它是 4095 个字符,或者在位置 4096 有一些特殊的东西。
std::getline
没有缓冲区大小限制。