I have tried all possibilities I could, and failed to find solution. Please help
I want to remove records in vector in map while iterating over it.
map < string, vector < record> >::iterator map_it;
for(map_it = map_records.begin(); map_it != map_records.end(); ++map_it){
vector < record>::iterator vec_it;
for(vec_it = (*map_it).second.begin(); vec_it != (*map_it).second.end();){
if(condition){
cout << (*map_it).second.size() << endl;
vec_it = map_it->second.erase(vec_it);
cout << (*map_it).second.size()<< endl;
} else {
++vec_it;
}
}
}
I tried something like this,
(*map_it).second.erase(vec_it)
It give some long number if I query the size of it and program ends with segmentation fault
OUTPUT:
18446744073709551615
18446744073709551615
Segmentation fault
Any help appreciated
You also need to check it’s validity immediately, so better re-write the inner loop as: