I am using the following code for reading lines from a text-file. What is the best method for handling the case where the line is greater than the limit SIZE_MAX_LINE?
Don't use istream::getline()
. It deals with naked character buffers and is therefor prone to errors. Better use std::getline(std::istream&,std::string&, char='\n')
from the
header:
std::string line;
while(std::getline(xInFile, line)) {
m_sStream.append(line);
m_sStream.append('\n'); // getline() consumes '\n'
}