iostream status is not predictive. It reports the results of the
previous operation, not of the next (which would be impossible to
implement anyway). And myfile.good() isn't even a reliable indicator
of the results of the previous operation: if the operation failed, it
will be false, but if the operation succeeded, it's not necessarily
true. Forget that function.
Use the fact that the stream can act as a boolean to test success of the
previous operation. Once you have failure, you can then use eof(),
and bad() to determine why (but with regards to eof(), only after
failure---eof() may return true even if the previous operation
succeeded). Thus:
while ( myfile >> name >> phone ) {
// ...
}
if ( myfile.bad() ) {
std::cerr << "Hardware read error" << std::endl;
} else if ( !myfile.eof() ) {
std::cerr << "Format error in file" << std::endl;
}