Contents Up << >>

Why does my input seem to process past the end of file?

Because the eof state is not set until after a read is attempted past the end of file. That is, reading the last byte from a file does not set the eof state.

If your code looks like this:

  	int i = 0;
	while (! cin.eof())  {
	  cin >> x;
	  ++i;
	  // work with x
	}
Then you have an off by one error with the count i. What you really need is:

  	int i;
	while (cin >> x)  {
	  ++i;
	  // work with x
	}