For example while(getline( , ))
when is this kind of condition true/false and why are they used instead of other situational conditions?
For example while(getline( , ))
when is this kind of condition true/false and why are they used instead of other situational conditions?
when is this kind of condition true/false
Given the documentation of std::getline()
which says the return value is the std::istream
reference of the stream that is involved in the operation, it isn't obvious how that stream evaluates to true
or false
.
This is done using the overloaded cast operator to bool
inherited from the std::ios
class.
This class defines the state flags indicating the current stream state, and true
will be only evaluated if the stream state is good
, other states like eof
or fail
will evaluate to false
.
and why are they used instead of other situational conditions?
Highly related Q&A: Why is iostream::eof inside a loop condition considered wrong?