http://blog.csdn.net/ly21st http://ly21st.blog.chinaunix.net
分类: C/C++
2011-11-20 19:20:28
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
练习1编写一个函数,其唯一的形参和返回值都是istream&类型。该函数一直读取流直到文件结束符为止,还应将读取的内容输出到标准输出中。最后,重设流使其有效,并返回该流。
#include
#include
using namespace std;
#include
#include
istream& get(istream &in)
{
int ival;
while(in>>ival,!in.eof()) {
if(in.bad() )
throw runtime_error("io stream error\n");
if (in.fail()) {
cerr<<"bad data, try again\n";
in.clear();
in.ignor(200,' ');
continue;
}
cout<
}
in.clear();
return in;
}
int main()
{
get(cin);
getchar();
getchar();
}