小编Sha*_*thi的帖子

c++ 中 m.erase() 函数的奇怪行为?

int main(){
    map<int, int> m;
    m.insert({1,2});
    m.insert({2,3});
    m.insert({5,10});
    m.erase(m.find(3));
    for(auto &x: m){
        cout<<x.first<<" "<<x.second<<nl;
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

1 2
5 10
Run Code Online (Sandbox Code Playgroud)

据我所知,m.find(3)将迭代器返回到m.end()if 键未找到。那为什么要删除 {2,3} 对呢?

c++ dictionary stl ordered-map

0
推荐指数
1
解决办法
70
查看次数

标签 统计

c++ ×1

dictionary ×1

ordered-map ×1

stl ×1