I have declared,

map<int, vector<int>> abcmap;
map<int,vector<int>>:: iterator itmap;

vector<int>SPLINKS;

SPLINKS contains:

1 3 4

abcmap contains;

1=> 1

2=> 2 6

3=> 1 2 4

I want to iterate both SPLINKS and abcmap to find and erase elements that do not match in both containers;

ie after execution;

2=>2 6 //not matched with either 1 or 3 or 4

I write something like;

for(itmap = abcmap.begin(); itmap != abcmap.end(); ++itmap)
{
cout << endl << itmap->first <<" => ";
for(size_t n=0; n<(*itmap).second.size(); n++)
{
for(itspl=SPLINKS.begin(); itspl!=SPLINKS.end(); ++itspl)
{
if((*itspl)==itmap->second[n])
{
    abcmap.erase(itmap);
}
}
}
}

But I get debug assertion failed! in both cases.

Can anyone say how to overcome this problem?

Given

SPLINKS contains:

1 3 4

abcmap contains;

1=> 1

2=> 2 6

3=> 1 2 4

What should the results be when the operation is finished?

Maybe this?

SPLINKS contains:

1 4

abcmap contains;

1=> 1

2=> 

3=> 1 4

No, I want to delete the entries 1=>1 and 3=>1 4 (because the values are matches with SPLINKS vector) the result must be,

1=> 2  6

when the operation is finished.
Since 2=>2 6 comes as the first key after deleting key 1 and 3.

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.