Is there any way (for example, some kind of coding convention with which I could follow now) that I could prevent this from harming me?
This may sound funny, but: after reading the documentation.
Since what you did is the somewhat expected behavior of the card, you cannot do it to protect it.
In the future, the following may be considered. In the second step, you did something wrong:
Check the return value, and if NULL use insert to insert a new element on the map.
, ++ ( C new): , - , NULL ( 0 nullptr) . ( , operator [] . obvoiusly (, )).
, , , , , end() .
, ( NULL), NULL, , 0 ++, .
++ 11 , nullptr, , . , : NULL, ++ 11 nullptr.