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 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用