The base classes istream
and ostream
have implicit function conversions that allow them to be used as a logical value; in pre-C ++ 11, the implicit conversion was void*
.
It was never intended that the result of this conversion be used as a pointer, and code like fin == NULL
shows an extremely poor understanding of C ++ and standard threads. The idiomatic way of writing the first loop would be to define a default constructor and operator>>
for Person
, and then write:
Person p; while ( fin >> p ) { v.push_back( p ); }
(And while I'm in: you really have to check the return value of fin.close()
and not return 0
if that fails:
fin.close(); return fin ? EXIT_SUCCESS : EXIT_FAILURE;
.)
source share