实现关于C++过滤掉关键字的小程序
2014-04-27 来自:潇潇雨尘 0 人回应
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应该怎么做

还没有人回应!

您的回应

你还未登陆,不能回应!登陆