小编Aka*_*lva的帖子

找到向量c ++中最长的单词

所以我有一个包含大约 106 千个单词的 c++ 向量,这些单词存储在vector<string>words 我需要找到这个向量中最长的单词,我还需要获取单词所在的位置,例如 (1,2,3) 在我的向量。我需要这个位置,因为我还有另外两个具有单词含义和类型的向量。vector<string>definition, vector<string>type 请帮忙

我当前的代码

此代码根本不起作用

copy_if(words.begin(), words.end(), back_inserter(length), [](const string& x) { return x.length() > 40; });// looks for words longer than 7 letters
   
    for (const string& s : length)
    {
        cout << "found!!" << endl;
        auto i = find(words.begin(), words.end(), s);//looks for the word in the words vector
        if (i != words.end())
        {
            auto pos = i - words.begin();
            //displays the word, type and the definition of the word that …
Run Code Online (Sandbox Code Playgroud)

c++ search

0
推荐指数
1
解决办法
691
查看次数

标签 统计

c++ ×1

search ×1