Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

buffer size limit for getline in C++

Tags:

c++

file

getline

I have a simple C++ program which reads a file line by line. Some lines contain more than 20000 characters. The following program can only read 4095 characters of those big line. I think it is because of the buffer size limit. What is the solution to read the big 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;
    }
like image 978
CPP_NEW Avatar asked Aug 23 '16 17:08

CPP_NEW


1 Answers

Try sed ${n}p | wc on your input, where n is the line number in question. My guess is wc will report it to be 4095 characters, or there's something special at position 4096.

std::getline has no buffer-size limitation, per the standard.

like image 91
James K. Lowden Avatar answered Sep 25 '22 21:09

James K. Lowden