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 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺