What is the preferred/idiomatic way to insert into a map?

前端 未结 9 1476
感动是毒
感动是毒 2020-11-28 18:45

I have identified four different ways of inserting elements into a std::map:

std::map function;

function[0] = 42;
function.inse         


        
9条回答
  •  被撕碎了的回忆
    2020-11-28 18:58

    If you want to overwrite the element with key 0

    function[0] = 42;
    

    Otherwise:

    function.insert(std::make_pair(0, 42));
    

提交回复
热议问题