Buffer size limit for getline in C ++

I have a simple C ++ program that reads a file line by line. Some lines contain more than 20,000 characters. The following program can only read 4095 characters of this large line. I think this is due to buffer size limitation. What is the solution for reading large lines?

// 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;
    }
+4
source share
1 answer

Try sed ${n}p | wcat your input, where nis the line number in question. I assume that wc will report that it should be 4095 characters, or there is something special in position 4096.

std::getline has no restrictions on the size of the buffer, according to the standard.

+2
source

Source: https://habr.com/ru/post/1652229/


All Articles