Saturday, 24 August 2013

Sort Vector in a Map c++

Sort Vector in a Map c++

I'm trying to sort some vectors inside my map, but when I run the program
I have a Segmentation Fault.
typedef map<int, vector<int> > Map;
Map m;
for (Map::iterator it = m.begin(); it != m.end(); ++it) {
sort(it->second.begin(), it->second.end());
}
Just before the sort I have a section that insert datas:
int x = 2;
int y = 3;
map<int, vector<int> >::iterator itTemp;
itTemp = FontaneMapX.find(x);
if (itTemp == m.end())
itTemp = m.insert(make_pair(x,vector<int>())).first;
itTemp->second.push_back(y);
I don't remove/add items after this section, not event to the vectors
inside the map.
Any ideas on what I should change?

No comments:

Post a Comment