Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 映射/集迭代器不可递增_C++_Visual Studio 2010_Stl - Fatal编程技术网

C++ 映射/集迭代器不可递增

C++ 映射/集迭代器不可递增,c++,visual-studio-2010,stl,C++,Visual Studio 2010,Stl,我在visual studio 2010中遇到了下面代码中的“map/set iterator not incrementable”运行时错误,我自己无法解决。。这是一个依赖于平台的问题吗?下面详细列出了整个代码部分。请帮帮我,谢谢 #include <vector> #include <map> #include <string> #include <iostream> using namespace std; void printHighCha

我在visual studio 2010中遇到了下面代码中的“map/set iterator not incrementable”运行时错误,我自己无法解决。。这是一个依赖于平台的问题吗?下面详细列出了整个代码部分。请帮帮我,谢谢

#include <vector>
#include <map>
#include <string>
#include <iostream>
using namespace std;
void printHighChangeables(const map<string,vector<string>>& , int );
map<string,vector<string>> computeAdjacentWords(const vector<string>& );

int main()
{

    string v1[16]={"wine","dine","fine","line","nine","pine","vine","kine","wind","wing",
        "wins","hoot","loot","soot","root","boot"};
    const vector<string> words (&v1[0], &v1[15]);

    map<string,vector<string>> adjWords = computeAdjacentWords(words);
    printHighChangeables(adjWords,3);
}

void printHighChangeables(const map<string,vector<string>>& adjWords, int minWords=3)
{
    map<string,vector<string>>::const_iterator itr;
    for(itr = adjWords.begin(); itr != adjWords.end(); itr++)
    {
        const pair<string,vector<string>>& entry = *itr;
        const vector<string> & words = entry.second;
        if(words.size() >= minWords)
        {
            cout<<entry.first<<"("<<words.size()<<"):";
            for (int i = 0; i<words.size(); i++)
                cout<<" "<<words[i];
            cout<<endl;
        }
    }
}


//computes a map in which the keys are words and values are vectors of words
//that differ in only one character from the corresponding key
//Uses an efficient algorithm that is O(NlogN) with a map
map<string,vector<string>> computeAdjacentWords(const vector<string>& words)
{
    map<string,vector<string>> adjWords;
    map<int,vector<string>> wordsByLength;
    for(int i=0; i<words.size(); i++)
        wordsByLength[words[i].length()].push_back(words[i]);
    //work on each group separately
    map<int,vector<string>>::const_iterator itr;
    for(itr=wordsByLength.begin(); itr!=wordsByLength.end();itr++)
    {
        const vector<string>& groupsWords = itr->second;
        int groupNum = itr->first;
        //work on each position in each group
        for(int i = 0; i<groupNum; i++)
        {
            //Remove a character in given position, computing representatives
            //Words with same representatives are adjacent; so populate a map
            map<string,vector<string>> repToWord;
            for(int j=0; j<groupsWords.size(); j++)
            {
                string rep = groupsWords[j];
                rep.erase(i,1);
                repToWord[rep].push_back(groupsWords[j]);
            }
            map<string,vector<string>>::const_iterator itr2;
            for(itr2 = repToWord.begin(); itr2 != repToWord.end(); itr++)
            {
                const vector<string> & clique = itr2->second;
                if(clique.size() >= 2)
                    for(int p=clique.size(); p<clique.size(); p++)
                        for(int q=p+1; q<clique.size(); q++)
                        {
                            adjWords[clique[p]].push_back(clique[q]);
                            adjWords[clique[q]].push_back(clique[p]);
                        }
            }
        }
    }
    return adjWords;
}
#包括
#包括
#包括
#包括
使用名称空间std;
无效的可打印高易变项(常量映射和int);
映射计算相邻词(常量向量&);
int main()
{
字符串v1[16]={“酒”、“餐”、“细”、“线”、“九”、“松”、“藤”、“牛”、“风”、“翼”,
“胜利”,“鸣笛”,“战利品”,“煤烟”,“根”,“靴子”};
常量向量词(&v1[0],&v1[15]);
映射邻接词=计算邻接词(词);
可打印高易变内容(adjWords,3);
}
void printHighChangeables(常量映射和形容词,int-minWords=3)
{
map::const_迭代器itr;
for(itr=adjWords.begin();itr!=adjWords.end();itr++)
{
常量对和条目=*itr;
常量向量&words=entry.second;
if(words.size()>=minWords)
{

cout此循环增加了错误的迭代器:

for(itr2 = repToWord.begin(); itr2 != repToWord.end(); itr++)
                                              //       ^^^^^  should be itr2

太多的代码无法阅读…您是否有可能在迭代时修改
映射