#include<iostream>
#include<stdexcept>
using namespace std;
istream& get(istream& in)
{
int value;
cout<<"input int! \n";
while(in>>value,!in.eof())//逗号表达式,将最后一个做为其值,所以,此处只有遇到文件结束符才结束循环!!!
{
if(in.bad())
{cout<<"bad";throw runtime_error("in stream corrupted");}
else if(in.fail()) //类中定义的所以要加::
{cerr<<"date fail,try again!!!\ninput int!\n";in.clear(istream::failbit);in.ignore(200,' ');continue;}
else {cout<<value<<endl;cout<<"input int!\n";}
}
in.clear();
return in;
}
int main()
{
get(cin);
}
#include<stdexcept>
using namespace std;
istream& get(istream& in)
{
int value;
cout<<"input int! \n";
while(in>>value,!in.eof())//逗号表达式,将最后一个做为其值,所以,此处只有遇到文件结束符才结束循环!!!
{
if(in.bad())
{cout<<"bad";throw runtime_error("in stream corrupted");}
else if(in.fail()) //类中定义的所以要加::
{cerr<<"date fail,try again!!!\ninput int!\n";in.clear(istream::failbit);in.ignore(200,' ');continue;}
else {cout<<value<<endl;cout<<"input int!\n";}
}
in.clear();
return in;
}
int main()
{
get(cin);
}