简体   繁体   中英

Insertion into map in c++

So, I was going through code on geeksforgeeks for checking which array is lesser of two given arrays. I came across this code snippet and is confused about the usage of the maps.

   map<int, int> mp1; 

   for (int i = 0; i < m; i++) 
       mp1[a[i]]++; 

Here a[i] is the array given and m is the size of the array.

So, Here how they have used map to insert array elements and if so what would be the key values.

std::map::operator[] will insert the element if it doesn't already exist.

See https://en.cppreference.com/w/cpp/container/map/operator_at

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM