My college senior told me that if I make iterator to multiset and insert in the multiset it would not break the iterator. Is it true?
Multiset can change value at the iterator too after insertion so it wont break the iterator?
Causes reallocation if the new size() is greater than the old capacity(). If the new size() is greater than capacity(), all iterators and references are invalidated. Otherwise, only the iterators and references before the insertion point remain valid. The past-the-end iterator is also invalidated.
set and multiset are normally implemented as binary search trees (https://en.wikipedia.org/wiki/Binary_search_tree). Each value is stored in a node, and an iterator just points to one of these nodes. Inserting a new element just means that you add a new node, and change the connections (pointers) from some of the other nodes, but all of the existing nodes are still valid and contain the same values which means there is no problem to keep using the iterators.
A vector is implemented using an array (https://en.wikipedia.org/wiki/Dynamic_array). A vector iterator is essentially a pointer to one of the elements in the array. If the vector runs out of space it has to allocate a new array and copy the values over. This means that iterators and pointers are no longer valid, because they point to the old array that has just been deleted.