RT•Definea function that, given an istream& and a constvector&, produces a map> holding each string (keyword) and the numbers of the line on which thestring appears. The line number of the first line is 1. •Printin the order of ascending keyword.•Runthe program on a text file with at least 10000 lines looking for no fewer than10 keywords.窝只是想问问怎么在一个vector里查找另一个……!求教!!
keywords.txt用来存放需要寻找的关键词
text是一个大文本
result 是存放结果的txt
然后要做的就是寻找keywords.txt里的关键词在text.txt里出现的行数
我的程序已经能实现的部分是把keywords.txt里的单词分割,把text.txt一行一行分割
就是不清楚怎么查找……还有存入map也辛苦大家讲一下辣
#include
#include
#include
#include
#include
using namespace std;
int main()
{ ifstream inf1("F:\keywords.txt");
ifstream fin("F:\text.txt");
ofstream fout("F:\result.txt");
string word; vector vts;vector vts2;int i=0;int j=0;
int cnt=0;int cnt2=0; while (inf1>>word)
{
cnt++;
vts.push_back(word);
}
/********************************************/
cnt=0;while (getline(fin,word))
{
cnt2++;
vts2.push_back(word);
}
/**********************************************/
for(i=0;i
{
for(j=0;j
{
vector::iterator x;
if ( (x=std::find(vts2.begin(),vts2.end(),vts[j])) !=vts2.end() )
cout<<i<<"\n";
}
}
inf1.close();
fin.close();
fout.close();
return 0;
}