检测到EOF后,cin将两位(eofbit和failbit)都设置为1,
应将cin.eof()或cin.fail()测试放在读取后
cin.fail()可用于更多的实现中
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
char ch;
cout<<"Enter characters:enter # to quit:\n";
int count = 0;
cin.get(ch);
while (cin.fail()==false)
{
++count;
cout<<ch;
cin.get(ch);
}
cout<<endl<<count<<"characters read\n";
system("pause");
return 0;
}