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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With