I have delared two multimaps such as;

multimap<int,vector<int>> allpathsmap;            
multimap<int,vector<int>>:: iterator itapm; 
typedef pair<int,vector<int>> pairapm;

multimap<int,vector<int>> graphtextmap;           
multimap<int,vector<int>>:: iterator itgtm; 
typedef pair<int,vector<int>> pairgtm;

And I wrote the following code to traverse the values of multimaps to print the key;

for(itgtm=graphtextmap.begin(); itgtm!=graphtextmap.end(); ++itgtm)
{
    for(itapm=allpathsmap.begin(); itapm!=allpathsmap.end(); ++itapm)
    {
        cout << endl << itapm->first <<" => ";
        for(size_t m=0 ; m<(*itgtm).second.size(); ++m )
        {
            for(size_t n=0; n<(*itapm).second.size(); ++n)
            {       
                if((itgtm->second[n]==itapm->second[m])&&(itgtm->second[n+1]==itapm->second[m+1]))
                {
                    cout<<itgtm->first;           
                }
            }
        }
    }
}

From the code I get debug assertion failed as "vector subscript out of range".
Can ony one please fix the problem?

Have a look at line 10. What happens when either n or m reference the last vector index?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.