Good question. It would be nice to catch the other failures in this call, but continue normally when it gets into eof.
However, I have not used thread exceptions before. I think you could make a copy and check the status of the stream afterwards to detect other errors, for example:
ifstream ifs(argv[1]); if (!ifs) { cerr << "Couldn't open " << argv[1] << '\n'; return -1; } //ifs.exceptions(ios::failbit | ios::badbit); istream_iterator<std::string> iss(ifs), iss_end; copy(iss, iss_end, ostream_iterator<std::string>(cout, "\n")); if (!ifs.eof()) { cerr << "Failed to read the entire file.\n"; return -2; }
source share