too complicated. One of the examples:

while( !input.eof() )
{
      // read message
      if ( input.eof() )
            break;
}