Why C++ map.insert() doesn't overwrite

前端 未结 5 1375
误落风尘
误落风尘 2021-01-17 20:25

In the code below:

#include 
#include 
#include 

using namespace std;

int main(){
  pair p1(1,1);
         


        
5条回答
  •  时光说笑
    2021-01-17 21:02

    It doesn't overwrite. However if you check the return value, there is a std::pair. If bool is true, then it was inserted. If the bool is false, then it was not inserted because of a collision. At that point, you can then overwrite the data yourself by writing to the iterator.

提交回复
热议问题