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 …

Member Avatar
Member Avatar
+0 forum 2

Hello everyone! I would like your help regarding this: I have a tuple vector which i must iterate through, and accessing the vector data to decide wether to erase or not the current vector element. My code : typedef tuple <int, CString, int, int> pc_data; vector <pc_data> pc_vec; //Assume that pc_vec is filled with elements somewhere here... //This code is not working. //Exception : vector subject out of range because of the size dynamically changing i suppose for (int i=0; i<num_of_pcs; i++) { if(std::get<2>(pc_vec[i])==0) pc_vec.erase(pc_vec.begin()+i); } //second try //No exception here but the dynamic size of the vector again won't …

Member Avatar
Member Avatar
+0 forum 6

The End.