急求C++高手:关键字过滤程序

来源:百度知道 编辑:UC知道 时间:2024/05/27 21:29:55
用STL的Iterators
关键字过滤程序:为了防止不法分子利用互联网危害社会,往往需要对网络上的一些敏感信息进行关键字过滤,例如google,baidu等搜索引擎都提供了敏感关键字的过滤功能。现在要求实现一个简单的关键字过滤程序,具体要求如下:

1. 从文件input.txt中读入内容,并检查内容中是否存在应该过滤的敏感词汇。
2. 所有的敏感词汇保存在ForbiddenWords.txt中。
3. 检查input.txt中的敏感词汇是否大于5个。如果大于5个,则输出一个output.txt文件,里面内容为“非法文档”;否则,输出一个output.txt文件,里面的内容为input.txt中所有敏感词汇出现的地方用“为奥运加油”代替以后的内容。
越快越好,今天下午4.30要交的

#include <vector>
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>

using namespace std;

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

int main(int argc, char* argv[])
{
vector<string> vec1;
vector<string> 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<<"文件打不开!!!"<<endl;
return 1;
}
copy(istream_iterator<string>(record_file1), istream_iterator<string>(), back_inserter(vec1));
copy(istream_iterator<string>(record_file2), istream_iterator<string>(), back_inserter(vec2));

vector<string>::iterator