std::getline throwing when it hits eof
问题 std::getline throws exception when it gets an eof . this is how I am doing. std::ifstream stream; stream.exceptions(std::ifstream::failbit|std::ifstream::badbit); try{ stream.open(_file.c_str(), std::ios_base::in); }catch(std::ifstream::failure e){ std::cout << "Failed to open file " << _file.c_str() << " for reading" << std::endl; } while(!stream.eof()){ std::string buffer = ""; std::getline(stream, buffer); //process buffer //I do also need to maintain state while parsing } In the above