O
Old Wolf
Code snippet:
std::ifstream file( "does_not_exist" );
std::vector<char> file_vec;
std::copy( std::istream_iterator<char>(file),
std::istream_iterator<char>(), std::back_inserter(file_vec) );
if ( file_vec.empty() )
// file did not exist or had no contents..
I expected this to work, and have the istream_iterator for
closed file return a blank iterator, so the copy would not
copy anything. But it segfaults. Is the behaviour
undefined or is my compiler broken?
std::ifstream file( "does_not_exist" );
std::vector<char> file_vec;
std::copy( std::istream_iterator<char>(file),
std::istream_iterator<char>(), std::back_inserter(file_vec) );
if ( file_vec.empty() )
// file did not exist or had no contents..
I expected this to work, and have the istream_iterator for
closed file return a blank iterator, so the copy would not
copy anything. But it segfaults. Is the behaviour
undefined or is my compiler broken?