C ++中getline的缓冲区大小限制

CPP*_*NEW 5 c++ file 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;
    }
Run Code Online (Sandbox Code Playgroud)

Jam*_*den 3

尝试sed ${n}p | wc输入您的输入,n有问题的行号在哪里。我的猜测是 wc 会报告它是 4095 个字符,或者在位置 4096 处有一些特殊的东西。

std::getline根据标准,没有缓冲区大小限制。