For inserting new elements in map, we can use insert member function.
To know if an element exists or not in a map, we can use count or find
member function.
Also, we can use the iterator returned by find to modify the mapped
value of an existing key.
When we use operator[], it may add an element into the map if the key
already doesn't exist, which may not be always wanted.
Given this, I am unable to understand the reason as to why we have
operator[] in map whose functionality can be achieved by other member
functions.
Kindly clarify.
Thanks
V.Subramanian
To know if an element exists or not in a map, we can use count or find
member function.
Also, we can use the iterator returned by find to modify the mapped
value of an existing key.
When we use operator[], it may add an element into the map if the key
already doesn't exist, which may not be always wanted.
Given this, I am unable to understand the reason as to why we have
operator[] in map whose functionality can be achieved by other member
functions.
Kindly clarify.
Thanks
V.Subramanian
Comment