0

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?

2
Contributors
2
Replies
24
Views
3 Years
Discussion Span
Last Post by shelton22
0

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
0

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.

Edited by shelton22

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.