What happens if I read a map's value where the key does not exist?

前端 未结 7 1137
孤独总比滥情好
孤独总比滥情好 2020-12-05 12:24
map dada;
dada[\"dummy\"] = \"papy\";
cout << dada[\"pootoo\"];

I\'m puzzled because I don\'t know if it\'s considered

7条回答
  •  庸人自扰
    2020-12-05 13:02

    For operator[], if you try to access a value for a key that doesn't exist, a new value object that has been default constructed will be put into the map and it's reference returned.

提交回复
热议问题