#include <vector>
#include <istream>
struct Foo {
int a;
}
std::istream & operator>> ( std::istream & lhs, Foo & rhs ) {
int a = 0;
if ( lhs >> a ) {
rhs.a = a;
}
return lhs;
}
std::vector<Foo> read( std::istream & is ) {
std::vector<Foo> result;
result.reserve( 12 );
Foo foo;
while ( is >> foo ) // this ends when input fails, be it string or EOF.
{
result.push_back( foo );
}
return result;
}
However, why does your program use a hardcoded name for the inputfile? Could it read standard input instead? It is trivial to redirect the content of file into standard input of a program.
Furthermore, it is trivial with GNU tools to pipe all but the last line of a file into another program. Thus, your program would never see the offending line.