#include <fstream>
#include <iostream>
#include <vector>
#include<string>
using namespace std;
istream& get(istream& in)
{
int ival;
while(in >> ival, !in.eof())
{
if(in.bad())
throw runtime_error("IO stream corrupted");
if(in.fail())
{
cerr << "bad data , try again";
in.clear();
in.ignore(20,' ');
continue;
}
cout << ival <<" ";
}
in.clear();
return in;
}
void process(string s)
{
cout << s.c_str() <<endl;
}
void main()
{
fstream input;
vector<string> files;
string fileName,s;
int ival;
cout << "Enter filenames:(ctrl+z to end)"<<endl;
do
{
cin >> fileName;
files.push_back(fileName);
cout << "按1继续添加:";
cin >> ival;
}while(ival == 1);
vector<string>::const_iterator it = files.begin();
while(it != files.end())
{
input.open(it->c_str());
if(!input)
{
cerr << "error: can not open file:"
<< *it << endl;
input.clear();
++it;
}
else
{
while(input >> s)
{
process(s);
}
input.close();
input.clear();
++it;
}
}
}