![]() |
In C++, maps are STL containers that store key-value pairs and maintain the element’s order according to their keys. Pairs also store the data as key values. In this article, we will discuss how to insert a pair into a map in C++. For Example, Input: map<int, string> mp = {(1, "geek"), (2,"for")} pair<int, string> pr = {3, "geeks"} Output: // after inserting pr to mp mp = {(1, "geek"), (2,"for"), (3, "geeks")} Insert Pair into a Map in C++Pairs can be inserted directly into the map container by using the std::map::insert() function. We just need to pass the said pair as an argument to this function. C++ Program to Insert Pair into a MapC++
Output
Contents of the map: Key: 25, Value: GeeksforGeeks We can also use std::map:: |
Reffered: https://www.geeksforgeeks.org
C++ |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |