unsafe and too complicated
you can use 
while( !input.eof() )
{
...
}