Hey. I've got this function.. I'm trying to test if the file passed in is completely empty... if it is, I return early for certain reasons. I'm just wondering how I can do this in the most elegant way... what I have above (in bold) doesn't work. I debugged it and the if statement body never gets reached.Code:#include <fstream> #include <iterator> #include <algorithm> #include <string> // Reads data from a file. // - Requires that Object has an overloaded >> operator. // - Returns a Container of Objects. // - Returns early if file is empty. template <typename Object, typename Container> Container read_data(std::istream& file) { Container v; if(file.eof()) { // Empty; return early. return v; } std::copy( std::istream_iterator<Object>(file), std::istream_iterator<Object>(), std::back_inserter(v)); return v; }
Cheers.




Reply With Quote