您的位置:首页 > 其它

流对象的使用2

2016-02-22 21:20 351 查看
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

void process(string s)
{
cout << s << endl;
}

int main()
{
vector<string> files;
files.push_back("one.txt");
files.push_back("two.txt");
files.push_back("three.txt");
string s;
vector<string>::const_iterator it = files.begin();
while (it != files.end())
{
ifstream input(it->c_str());
if (!input)
{
cerr << "error: can not open file? " << *it << endl;
input.clear();
++it;
continue;
}
while (input >> s)
process(s);
input.close();
input.clear();
++it;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: