vector map 容器删除 2020-09-22 技术 Contents vector 删除 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 std::vector<int> v; void erase_vector(int val) { for(auto iter = v.begin(); iter != v.end(); ) { if(*iter > val) { iter = v.erase(iter); } else { iter++; } } } map 删除 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 std::map<int, int> m; void erase_map(int val) { for(auto iter = m.begin(); iter != m.end(); ) { if(iter->second > val) { //iter = m.erase(iter); //c++ 11 m.erase(iter++); } else { iter++; } } } Author ai0376 LastMod 2020-09-22 Reward wechat