为什么cin对fail的检查总是滞后一位?

下面是我的代码:
int main()
{
using namespace std;

char ch;
int count = 0;

cout << "Enter a sentence : ";
while (ch=cin.get()!=EOF)
    count++;

cout << "The last ch is: " << ch << endl;
cout << "You have entered " << count << " chars." << endl;

return 0;

}
如果输入是“I”+,那么这里的输入总是对EOF没有反应,无法终止循环,再单独输入一个EOF才能终止;如果直接输入EOF反而可以直接终止,有哪位大牛能说明一下为什么会这样?

EOF需要用文件输入才可以终止,要不就用CTRL+C
例:#include
#include
int main()
{
using namespace std;
char ch;
int count = 0;
freopen("sample.in", "r", stdin);

freopen("sample.out", "w", stdout);

cout << "Enter a sentence : ";
ch=cin.get();
while (ch!=EOF)
count++,ch=cin.get();
cout << "The last ch is: " << ch << endl;
cout << "You have entered " << count << " chars." << endl;
fclose(stdin);

fclose(stdout);
return 0;
}
按照你程序意思,想要输出最后一个字符
然而只有读了EOF判断完了才可以输出
所以"The last ch is:
后面是空的
你自己改一下,加一个char类型,就可以实现目的
(用文件时不要打回车)
滑稽.opj____________________________________

char ch;
int count = 0;

cout << "Enter a sentence : ";
while (**(ch=cin.get())**!=EOF) 这里要括号。
count++;

cout << "The last ch is: " << ch << endl;
cout << "You have entered " << count << " chars." << endl;

return 0;