while (cin.peek() != EOF) { // To do your stuff... // NOTE: peek() will set failbit when peeking end of stream and return EOF(-1). }