Insertion and Deletion

In associative containers, values are inserted and deleted based on the keys they have.

The insertion (insert and emplace) and deletion (erase) of elements in associative containers is similar to the rules of an std::vector. For an associative container that can have a key only once, the insertion fails if the key is already in the container. Additionally, ordered associative containers support a special function ordAssCont.erase(key), which removes all pairs with the key and returns their number. See the usage of the function below.

Get hands-on with 1400+ tech skills courses.