Problem with Insertion of vector elements in a Map

to insert into map we use the the keywork insert().
But when we have a map of <int, vector >, how come we can just insert a value using map[index].push_back(value_for_vector)


map[index] inserts the value {index, default value} if it doesn’t already exist. So it adds the value to the vector at index, or creates an empty vector if it doesn’t already exist, and then adds the value to it.

1 Like