![]() |
In C++, a map is a container that stores elements in key-value pairs, where each key is unique and associated with a value. In this article, we will learn how to add multiple key-value pairs to a map in C++. Example: Input: myMap = { Map Multiple Key-Value Pairs in C++To map multiple key-value pairs to a std::map in C++, we can use the std::map::insert function that inserts key-value pairs into the map. The insert function can take a pair, a range of pairs, or an initializer list of pairs. Here, we will insert the range of pairs defined in the initializer list. C++ Program to Map Multiple Key-Value PairsC++
Output
Map after adding multiple key-value pairs: 1 => one 2 => two 3 => three Time Complexity: O(M logN), where M is the number of new pairs and N is the size of the map. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |