baidu_34303489 2016-04-04 16:59 采纳率: 0%
浏览 1602

大文件里查找单词的问题

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;
}

  • 写回答

1条回答

  • 小灸舞 2016-04-05 01:35
    关注
    #include<vector>
    #include<iostream>
    #include<algorithm>
    #include<string.h>
    #include<map>
    using namespace std;
    
    void main()
    {
        vector<int> a;
        a.push_back(3);
        a.push_back(4);
        a.push_back(5);
        vector<int>::iterator it;
        it = std::find(a.begin(), a.end(), 3);
        if(it == a.end())
            cout << "未找到元素3" <<endl;
        else
            cout << "找到了元素3" <<endl;
    
        map<string, int> b;
        b["aa"] = 5; //插入了key为"aa",value为5的键值对
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?