I want to read from a stream using std::getline
inside a for loop.
The stream I mean is a class inherited from the std::basic_iostream
.
std::string line; for(;;){ try{ std::getline( myStreamObj, line ); if( line != "" ){ std::cout << line << std::endl; } } catch( std::ios_base::failure& ex ){ std::cout << ex.what() << std::endl; } }
I want also to check against other error conditions like
eofbit failbit badbit
But I am bit confused about it.
If some of the conditions settings these 3 flags is met is any exception thrown like std::ios_base::failure
? How to handlse these 3 cases? Do I have to do checkings other ways?
Thanks AFG