I checked the C++11 standard and found the following facts:
std::getline(fin, str)
returns a basic_ios
object, whose class has a member function explicit operator bool() const;
The class basic_ios
doesn't have a member function operator void*() const;
as pre-C++11.
So, I think if (getline(fin, str)) {}
is not standard conforming. It should be written as
if (bool(getline(fin, str)){}
. (However, VC++ 2012 gives a warning on this usage. i.e. force void* to bool)
Am I correct?
The code is conforming. The explicit conversion operator to bool
will be called when the object is used as a condition automatically. The change in the standard was meant to maintain that same usage while making it a bit safer.
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