map::operator in C++ STL
Maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have same key values.
This operator is used to reference the element present at position given inside the operator. It is similar to the at() function, the only difference is that the at() function throws an out-of-range exception when the position is not in the bounds of the size of map, while this operator inserts a new element with that key and returns a reference to its mapped value, increasing the container size by one, the element is constructed using its default constructor if no value is provided.
mapname[key] Parameters : Key value mapped to the element to be fetched. Returns : Direct reference to the element at the given key value.
Input : map mymap; mymap['a'] = 1; mymap['a']; Output : 1 Input : map mymap; mymap["abcd"] = 7; mymap["abcd"]; Output : 7
mymap is GeeksForGeeks mymap is mymap now contains 5 elements.
Time Complexity: O(logn)