2 backspacee backspacee 于 2013.12.11 21:49 提问

实现关于C++过滤掉关键字的小程序
enter code here

#include
#include
#include
#include
#include

using namespace std;

ifstream& open_file(ifstream&, const string&);

int main(int argc, char* argv[])
{
vector vec1;
vector vec2;
ifstream record_file1;
ifstream record_file2;
open_file(record_file1,"input.txt");
open_file(record_file2,"ForbiddenWord.txt");
ofstream outfile("output.txt");
if(!record_file1.is_open() || !record_file2.is_open())
{
cout<<"文件打不开!!!"< return 1;
}
copy(istream_iterator(record_file1), istream_iterator(), back_inserter(vec1));
copy(istream_iterator(record_file2), istream_iterator(), back_inserter(vec2));

vector::iterator presult;
int count=0;
for(int i=0;i presult=find(vec1.begin(),vec1.end(),vec2[i]);
while(presult!=vec1.end()){
*presult = "为奥运加油";
++count;
presult=find(presult,vec1.end(),vec2[i]);
}
presult=find(presult,vec1.end(),vec2[i]);
}
if(count>=5)
outfile<<"非法文档";
else
copy(vec1.begin(), vec1.end(), ostream_iterator(outfile, " "));
cout << "文件已输出" << endl;
return 0;
}

ifstream& open_file(ifstream& in, const string& file)
{
in.close();
in.clear();
in.open(file.c_str());
return in;

}

这个小程序,麻烦大家能修改下吗,不能使用迭代器iterator,求大家修改下,换成list应该怎么做

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!