I’m trying to insert multiple times this same key into map but with different values. It doesn’t work. I know that operator[] does this job, but my question is, if this behaviour of insert is correct? Shouldn’t insert() inserts? I wonder what standard says. Unfortunately I don’t have it(Standard for C++) so I can’t check.
Thank you for helpful ansers.
I’m trying to insert multiple times this same key into map but with different
Share
If you want to insert the same key with different values, you need
std::multimapinstead.The
std::map::insertwill not do anything if the key already exists.The
std::map::operator[]will overwrite the old value.For STL reference you don`t necesary need the C++ standard itself; something like http://www.cplusplus.com/reference/ will do too.