If I understand correctly you want to be able of reading numbers after invalid input, right?
Do you want to get '5' from "sd5" or that each input is separated by a whitespace ( "sd5" would be invalid ) ?
sd5 would be invalid - i want to make such program, that any kind of combination of invalid (sd5 too) and valid inputs vould be recognised by the program
To discard input like "577sad" you can use this condition in the if: if ( myStream >> integer && myStream.eof() )
so it will perform lines 6-7 of the code in my last post only if after reading the number there are no other characters in the stream ( so you reach the end of it )