{"id":30282,"date":"2021-04-12T14:34:41","date_gmt":"2021-04-12T09:04:41","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/"},"modified":"2024-09-03T11:08:53","modified_gmt":"2024-09-03T05:38:53","slug":"map-in-c","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/","title":{"rendered":"Map in C++"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li><a href=\"#what\">What is MAP?<\/a><\/li>\n\n\n\n<li><a href=\"#container\">Containers Properties<\/a><\/li>\n\n\n\n<li><a href=\"#keyvalue\">Concept of Key-Value<\/a><\/li>\n\n\n\n<li><a href=\"#syntax\">The Generic Syntax of the Maps<\/a><\/li>\n\n\n\n<li><a href=\"#why\">Why We Use a Map?<\/a><\/li>\n\n\n\n<li><a href=\"#how\">How to Use Map?<\/a><\/li>\n\n\n\n<li><a href=\"#inbuilt\">Inbuilt Functions in Map<\/a><\/li>\n\n\n\n<li><a href=\"#type\">Member Type<\/a><\/li>\n\n\n\n<li><a href=\"#destructor\">Destructor in Map<\/a><\/li>\n\n\n\n<li><a href=\"#advan\">Advantages of Map<\/a><\/li>\n\n\n\n<li><a href=\"#disadvan\">Disadvantages of Map<\/a><\/li>\n\n\n\n<li><a href=\"#can\">Can we use the map in another map?<\/a><\/li>\n<\/ul>\n\n\n\n<p>In this article, you will learn about \u201cmap\u201d in the C++ programming language in detail. What is a map?&nbsp; Why we use a map? How to create a map? How to use a map in C++?&nbsp;<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-title-link\">C++ Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master key C++ programming concepts like variables, functions, OOP, and control structures. Build real-world projects such as a banking system and grade management tool.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Beginner to Advanced Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>8.1 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-map\"><strong>What is \u201cMAP\u201d?<\/strong><\/h2>\n\n\n\n<p>The map is a library of standard template library (STL). Now you think that what is STL?&nbsp;<\/p>\n\n\n\n<p>STL is a collection of generic classes and functions. It is used to increase the reusability of code that is already developed. It saves time. STL has three main components:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Containers<\/strong>: It stores the data and uses template classes.<\/li>\n\n\n\n<li><strong>Algorithms<\/strong>: It is a set of rules and uses template functions.<\/li>\n\n\n\n<li><strong>Iterators<\/strong>: It is an object that pointing to an element in the container. It handles just like a pointer.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"containers-properties\"><strong>Containers Properties<\/strong>:<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Associative<\/strong>: Elements stored in an associative array is pointed by their keys.<\/li>\n\n\n\n<li><strong>Ordered<\/strong>: Elements are stored in a container in a strictly ordered fashion.<\/li>\n\n\n\n<li><strong>Map<\/strong>: Each element has two parts. The first one is the key and the second one is mapped value through that key\u00a0<\/li>\n\n\n\n<li><strong>Uniqueness<\/strong>: Each element has a unique key.<\/li>\n\n\n\n<li><strong>Allocator-aware<\/strong>: It is responsible for dynamically storage allocation.<\/li>\n<\/ol>\n\n\n\n<p>Let us deep-dive, into the map:<\/p>\n\n\n\n<p>Map is an associative container\/array that store the elements as a combination of key-value pairs (just like a dictionary). Keys are in ascending order (By default).&nbsp;<\/p>\n\n\n\n<p><strong>Syntax<\/strong>:&nbsp; <em>map &lt; key_datatype, value_datatype &gt; map_name;<\/em><\/p>\n\n\n\n<p>Here, key_datatype = datatype of key<\/p>\n\n\n\n<p>value_datatype = datatypes of value corresponding to key&nbsp;<\/p>\n\n\n\n<p>map_name = Name of your map<\/p>\n\n\n\n<p>For example:&nbsp; <em>map &lt; string, int &gt; student_map;<\/em><\/p>\n\n\n\n<p>Here student_map is the name of the map,&nbsp;<\/p>\n\n\n\n<p>string and int are datatypes supported by map.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"concept-of-key-value\"><strong>Concept of key-value<\/strong>:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Each element has stored a key value and a mapped value.<\/li>\n\n\n\n<li>No two mapped value can have some key values.<\/li>\n\n\n\n<li>Each key has a corresponding one value.<\/li>\n<\/ul>\n\n\n\n<p>For example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Roll Num<\/td><td>Name<\/td><\/tr><tr><td>11<\/td><td>Dushyant<\/td><\/tr><tr><td>12<\/td><td>Mahiraj<\/td><\/tr><tr><td>13<\/td><td>Vipul<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-generic-syntax-of-the-map\"><strong>The generic<\/strong> syntax of the <strong>map:<\/strong><\/h2>\n\n\n\n<p><em>template &lt; class Key,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/em><em><\/em><em> \/\/ map::key_type<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class T,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/em><em><\/em><em> <\/em><em><\/em><em> \/\/ map::mapped_type<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class Compare = less&lt;Key&gt;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/em><em><\/em><em>\/\/ map::key_compare<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class Alloc = allocator&lt;pair&lt;const Key,T&gt; &gt;&nbsp; &nbsp; \/\/ map::allocator_type<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&gt; class map;<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-we-use-a-map\"><strong>Why we use a map?<\/strong><\/h2>\n\n\n\n<p>There are mainly two reasons for use map:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Faster access of data<\/strong>: Fast access of values of elements through the key.<\/li>\n\n\n\n<li><strong>No duplication of data<\/strong>: Every key is unique in the map so that duplication of data doesn\u2019t exist.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\"><\/h2>\n\n\n\n<p>Till now, we know that what is a map in C++ and the syntax of it. In this section we will learn how to create a map, initialization of map, accessing of map element. As we know the map store key-value pairs.<\/p>\n\n\n\n<p>To use map in c++ we must have to include &lt;map&gt; in our program i.e.<\/p>\n\n\n\n<p><em>#include &lt;map&gt;<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"declaration-of-map-in-c\"><strong>Declaration of map in C++:<\/strong><\/h3>\n\n\n\n<p><strong>Syntax<\/strong>:<\/p>\n\n\n\n<p><em>#include &lt;iostream&gt;<\/em><\/p>\n\n\n\n<p><em>#include &lt;map&gt;<\/em><\/p>\n\n\n\n<p><em>int main()<\/em><\/p>\n\n\n\n<p><em>{<\/em><\/p>\n\n\n\n<p><em>map&lt;key_datatype, value_datatype&gt; Map_name; <\/em><em><\/em><em> \/\/ declare a map<\/em><\/p>\n\n\n\n<p><em>return 0;<\/em><\/p>\n\n\n\n<p><em>}<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"initialization-of-map\"><strong>Initialization of map:<\/strong><\/h3>\n\n\n\n<p>In this section, we will know how to initialize the map. For inserting the elements in the map first we have to declare a map.<\/p>\n\n\n\n<p>i.e. <em>map&lt;key_datatype, value_datatype&gt; Map_name;<\/em><\/p>\n\n\n\n<p>we have three ways to insert elements in the map which are given below:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Initialize a map at the declaration\u00a0<\/strong><\/li>\n<\/ol>\n\n\n\n<p><strong>Syntax<\/strong>: <em>map&lt;key_datatype, value_datatype&gt;map_name {{key1, value1}, {key2, value2}, .., {key<\/em><em><sub>n<\/sub><\/em><em>,value<\/em><em><sub>n<\/sub><\/em><em>}};<\/em><\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Initialize a map using the insert function<\/strong><\/li>\n<\/ol>\n\n\n\n<p><strong>Syntax<\/strong>: <em>map&lt;key_datatype, value_datatype&gt;map_name;<\/em><\/p>\n\n\n\n<p><em>map_name.insert(pair&lt;key_datatype,&nbsp; value_datatype&gt;{key1, value1});<\/em><\/p>\n\n\n\n<p><em>map_name.insert(pair&lt;key_datatype,&nbsp; value_datatype&gt;{key2, value2});<\/em><\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Initialize a map using square brackets syntax<\/strong><\/li>\n<\/ol>\n\n\n\n<p><strong>Syntax<\/strong>: <em>map&lt;key_datatype, value_datatype&gt;map_name;<\/em><\/p>\n\n\n\n<p><em>map_name[key1] = value1;<\/em><\/p>\n\n\n\n<p><em>map_name[key2] = value2;<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"accessing-an-element-of-the-map\"><strong>Accessing an element of the map:<\/strong><\/h3>\n\n\n\n<p>We can access and manipulates the elements of the map in two ways:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Using square bracket<\/strong><\/li>\n<\/ol>\n\n\n\n<p><strong>Syntax<\/strong>: <em>\u2026<\/em><\/p>\n\n\n\n<p><em>cout &lt;&lt; map_name [key] &lt;&lt; endl;<\/em><\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p><strong>Explanation<\/strong>:&nbsp;<\/p>\n\n\n\n<p>We can access the value of any element in the map using its key as per the above syntax.<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Using at() function<\/strong><\/li>\n<\/ol>\n\n\n\n<p><strong>Syntax<\/strong>:<\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p><em>cout &lt;&lt; map_name.at(key) &lt;&lt; endl;<\/em><\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p>Explanation:<\/p>\n\n\n\n<p>We can access the value of any element in the map using at the () function which is an inbuilt function using the key as per the above syntax.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Accessing element using iterator:<\/strong><\/li>\n<\/ol>\n\n\n\n<p>We have a problem accessing every element in the map because the map has no index so that is why we have the concept of an iterator.<\/p>\n\n\n\n<p>As we studied in the above section iterators are treated as pointers that point elements in the container. So, for accessing a particular element in the map we use iterators.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Key<\/td><td>Value<\/td><\/tr><tr><td>First<\/td><td>Second<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Suppose,<\/p>\n\n\n\n<p>Iterator can access key and value using the first and second keyword.<\/p>\n\n\n\n<p><strong>Syntax<\/strong>:<\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p><em>map&lt;key_datatype,value_datatype&gt; :: iterator iterator_name;<\/em><\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p>e.g.&nbsp;<\/p>\n\n\n\n<p><em>map&lt;int, int&gt; :: iterator i;<\/em><\/p>\n\n\n\n<p><em>for(i=map_name.begin(); i!= map_name.end; i++)<\/em><\/p>\n\n\n\n<p><em>{&nbsp;<\/em><\/p>\n\n\n\n<p><em>cout&lt;&lt;(*i).first&lt;&lt; \u201d : \u201d &lt;&lt; (*i).second&lt;&lt;endl;<\/em><\/p>\n\n\n\n<p><em>}<\/em><\/p>\n\n\n\n<p>Here in the above example,<\/p>\n\n\n\n<p>Map_name.begin() return iterator to the beginning<\/p>\n\n\n\n<p>map_name.end() return iterator to the end.<\/p>\n\n\n\n<p>(*i).first =&gt; gives the key of the elements&nbsp;<\/p>\n\n\n\n<p>(*i).second =&gt; gives the values of the elements<\/p>\n\n\n\n<p>This example prints all the elements in the map.<\/p>\n\n\n\n<p>Let us take one example, suppose we want to store the mark of students where the key is the name of the student and the value is the mark.<\/p>\n\n\n\n<p>The name has the string Datatype while the mark has an integer datatype.<\/p>\n\n\n\n<p><strong>Program<\/strong>:<\/p>\n\n\n\n<p><em>#include&lt;iostream&gt;<\/em><\/p>\n\n\n\n<p><em>#include&lt;map&gt;<\/em><em> <\/em><em><\/em><em> <\/em><em>\/\/ for map<\/em><\/p>\n\n\n\n<p><em>#include&lt;string&gt; &nbsp; <\/em><em><\/em><em> <\/em><em><\/em><em>\/\/For string operations<\/em><\/p>\n\n\n\n<p><em>using namespace std;<\/em><\/p>\n\n\n\n<p><em>int main(){<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;map&lt;string, int&gt;student_map; &nbsp; \/\/ Declaration of Map<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;student_map [\"Mahiraj\"] = 87;&nbsp; \/\/ Inserting elements<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;student_map [\"Vipul\"] = 35;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;student_map [\"Dushyant\"] = 69;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;student_map.insert({{\"Jaydeep\",77},{\"Rajesh\",52}}); \/\/<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;map&lt;string,int&gt;::iterator itr;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;for(itr=student_map.begin(); itr!=student_map.end(); itr++)<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;(*itr).first&lt;&lt;\" : \"&lt;&lt;(*itr).second &lt;&lt;endl;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/em><\/p>\n\n\n\n<p><em>}<\/em><\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p><em>Dushyant: 69<\/em><\/p>\n\n\n\n<p><em>Jaydeep: 77<\/em><\/p>\n\n\n\n<p><em>Mahiraj: 87<\/em><\/p>\n\n\n\n<p><em>Rajesh: 52<\/em><\/p>\n\n\n\n<p><em>Vipul: 35<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"inbuilt-function-in-map\"><strong>Inbuilt function in \u201cMAP\u201d&nbsp;<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>begin()<\/strong> \u2013 it returns an iterator to the first element of map<\/li>\n\n\n\n<li><strong>end()<\/strong> \u2013 it returns an iterator that follows the last element of the map.<\/li>\n\n\n\n<li><strong>size()<\/strong> \u2013 it returns numbers of elements of the map.<\/li>\n<\/ol>\n\n\n\n<p>An example of size is :<\/p>\n\n\n\n<p><em>cout&lt;&lt;\u201dthe size is :\u201d&lt;&lt;student_map.size();<\/em><\/p>\n\n\n\n<p>This gives the size of the map<\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p>the size is:5<\/p>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>max_size()<\/strong> \u2013 it returns maximum size of elements in map.<\/li>\n<\/ol>\n\n\n\n<p>An example of max size is:<\/p>\n\n\n\n<p>\u2026<\/p>\n\n\n\n<p><em>cout&lt;&lt;\u201dthe max-size is :\u201d&lt;&lt;student_map.max_size();<\/em><\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p>This gives the maximum size of the map<\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p>The max-size is:97612893<\/p>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>empty()<\/strong> \u2013 it checks that whether the map is empty or not and returns boolean (true\/false).<\/li>\n<\/ol>\n\n\n\n<p>The example of empty() is:<\/p>\n\n\n\n<p>\u2026.<\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;\u201dmap is empty? :\u201d&lt;&lt;student_map.empty();<\/em><\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p>This gives the Boolean value 0=false &amp; 1=true.<\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p>map is empty? :0<\/p>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li><strong>insert(key,value)<\/strong> \u2013 it insert new element in map.<\/li>\n<\/ol>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p><em>map_name.insert({{key1,value1},{key2,value2}});<\/em><\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li><strong>erase (iterator location)<\/strong> \u2013 it removes the element which is specified at a location by the iterator.<\/li>\n<\/ol>\n\n\n\n<p>The example of erase() is:<\/p>\n\n\n\n<p>\u2026<\/p>\n\n\n\n<p><em>cout&lt;&lt;\u201dErase element:\u201d&lt;&lt;student_map.erase (\u201cMahiraj\u201d);<\/em><\/p>\n\n\n\n<p>\u2026<\/p>\n\n\n\n<p>This gives the Boolean value 0=false &amp; 1=true.&nbsp;<\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p>Erase element: 1<\/p>\n\n\n\n<ol start=\"8\" class=\"wp-block-list\">\n<li><strong>clear()<\/strong> \u2013 it deletes all the elements of the map.<\/li>\n<\/ol>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p><em>student_map.clear();<\/em><\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<ol start=\"9\" class=\"wp-block-list\">\n<li><strong>Find(loc)<\/strong> - it points to the element if element found at loc<\/li>\n<\/ol>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p><em>cout&lt;&lt;\u201dErase element:\u201d&lt;&lt;student_map.find (\u201cMahiraj\u201d);<\/em><\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<ol start=\"10\" class=\"wp-block-list\">\n<li><strong>swap()<\/strong> \u2013 it swaps the content of maps.<\/li>\n<\/ol>\n\n\n\n<p>The full program of swap function is below:<\/p>\n\n\n\n<p><em>#include &lt;iostream&gt;<\/em><\/p>\n\n\n\n<p><em>#include &lt;map&gt;<\/em><\/p>\n\n\n\n<p><em>#include &lt;string&gt; \/\/For sting operations<\/em><\/p>\n\n\n\n<p><em>using namespace std;<\/em><\/p>\n\n\n\n<p><em>int main()<\/em><\/p>\n\n\n\n<p><em>{<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;map&lt;string, int&gt; kk,dd;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;kk[\"Mahiraj\"] = 87;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;kk[\"Vipul\"] = 35;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;kk[\"Dushyant\"] = 69;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;dd.insert({{\"Jaydeep\", 77}, {\"Rajesh\", 52}});<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;kk.swap(dd);<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;map&lt;string, int&gt;::iterator itr;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;cout&lt;&lt;\"the kk map is :\";<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;for (itr = kk.begin(); itr != kk.end(); itr++)<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;{<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; (*itr).first &lt;&lt; \" : \" &lt;&lt; (*itr).second &lt;&lt; endl;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;}<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;cout&lt;&lt;\"the dd map is :\";<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;for (itr = dd.begin(); itr != dd.end(); itr++)<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;{<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; (*itr).first &lt;&lt; \" : \" &lt;&lt; (*itr).second &lt;&lt; endl;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;}<\/em><\/p>\n\n\n\n<p><em>}<\/em><\/p>\n\n\n\n<ol start=\"11\" class=\"wp-block-list\">\n<li><strong>count()<\/strong> \u2013 it returns the elements that match the specific key.<\/li>\n<\/ol>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<p><em>Student_map.count();<\/em><\/p>\n\n\n\n<p><em>\u2026<\/em><\/p>\n\n\n\n<ol start=\"12\" class=\"wp-block-list\">\n<li><strong>equal_range()<\/strong> \u2013 it returns a range of elements matching the specific key.<\/li>\n\n\n\n<li><strong>Upper_range()<\/strong> \u2013 Return iterator to the upper bound<\/li>\n\n\n\n<li><strong>lower_range()<\/strong> \u2013 Return iterator to the lower bound<\/li>\n\n\n\n<li><strong>key_comp()<\/strong> \u2013 it returns function that compares keys.<\/li>\n\n\n\n<li><strong>value_comp()<\/strong> \u2013 it returns function that compare keys in objects of type value.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"member-type\"><strong>Member Type:<\/strong><\/h2>\n\n\n\n<p>It is used as a parameter or return value in member function. Most of member types are listed below:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>key_type<\/li>\n\n\n\n<li>mapped_type<\/li>\n\n\n\n<li>value_type\u00a0<\/li>\n\n\n\n<li>key_compare<\/li>\n\n\n\n<li>value_compare<\/li>\n\n\n\n<li>allocator_type<\/li>\n\n\n\n<li>reference<\/li>\n\n\n\n<li>const_reference<\/li>\n\n\n\n<li>pointer<\/li>\n\n\n\n<li>const_pointer<\/li>\n\n\n\n<li>iterator<\/li>\n\n\n\n<li>const_iterator<\/li>\n\n\n\n<li>reverse_iterator<\/li>\n\n\n\n<li>const_reverse_iterator<\/li>\n\n\n\n<li>difference_type<\/li>\n\n\n\n<li>size_type<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"destructor-in-map\"><strong>Destructor in Map:<\/strong><\/h2>\n\n\n\n<p>It destroys the container object. It deallocates memory that allocates by the allocator during the construction of the map.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"advantages-of-the-map\"><strong>Advantages of the map:<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Map only stores unique keys which eliminates redundancy of data.<\/li>\n\n\n\n<li>Keys are always in sorted order which leads faster traversal in data.<\/li>\n\n\n\n<li>Easy to access the value using the key.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"the-disadvantage-of-the-map\"><strong>The disadvantage of the map:<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In the case of a large number of elements stored in the map, traversing to every element is more time-consuming.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"can-we-use-the-map-in-another-map\"><strong>Can we use the map in another map?<\/strong><\/h2>\n\n\n\n<p>Yes we can use nested map, but you have to keep the syntax of the&nbsp; map .<\/p>\n\n\n\n<p><em>#include &lt;iostream&gt;<\/em><\/p>\n\n\n\n<p><em>#include &lt;map&gt;<\/em><\/p>\n\n\n\n<p><em>#include &lt;string&gt;<\/em><\/p>\n\n\n\n<p><em>using namespace std;<\/em><\/p>\n\n\n\n<p><em>int main() {<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;map&lt;int, map&lt;string, int&gt; &gt; mapinmap;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;mapinmap[12][\"mahiraj\"]=87;<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;cout &lt;&lt;\u201dthe marks of roll no. 12&nbsp; mahiraj is :\u201d&lt;&lt; mapinmap[12][\"mahiraj\"] &lt;&lt; endl;<\/em><\/p>\n\n\n\n<p><em>}<\/em><\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p>the marks of roll no. 12&nbsp; mahiraj is:87<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"summary\"><strong>Summary:<\/strong><\/h2>\n\n\n\n<p>In this article, we learned what is a map in C++ in an easy manner. First, we learnt what is the map? Then we go through the STL, Creation of map, Initialization of map, how to access map? What is an iterator? and what iterators can do? Functions used in the map, member type used by the function, advantages and disadvantages of the map and the concept of a nested map.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, you will learn about \u201cmap\u201d in the C++ programming language in detail. What is a map?&nbsp; Why we use a map? How to create a map? How to use a map in C++?&nbsp; What is \u201cMAP\u201d? The map is a library of standard template library (STL). Now you think that what is [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":30295,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[],"content_type":[],"class_list":["post-30282","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Map in C++<\/title>\n<meta name=\"description\" content=\"In this article, you will learn about \u201cmap\u201d in the C++ programming language in detail. What is a map? Why we use a map? How to create a map? How to use a map in C++?\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Map in C++\" \/>\n<meta property=\"og:description\" content=\"In this article, you will learn about \u201cmap\u201d in the C++ programming language in detail. What is a map? Why we use a map? How to create a map? How to use a map in C++?\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-12T09:04:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-03T05:38:53+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Map in C++\",\"datePublished\":\"2021-04-12T09:04:41+00:00\",\"dateModified\":\"2024-09-03T05:38:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/\"},\"wordCount\":2048,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/shutterstock_528261487.jpg\",\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/\",\"name\":\"Map in C++\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/shutterstock_528261487.jpg\",\"datePublished\":\"2021-04-12T09:04:41+00:00\",\"dateModified\":\"2024-09-03T05:38:53+00:00\",\"description\":\"In this article, you will learn about \u201cmap\u201d in the C++ programming language in detail. What is a map? Why we use a map? How to create a map? How to use a map in C++?\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/shutterstock_528261487.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/shutterstock_528261487.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/map-in-c\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Map in C++\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Map in C++","description":"In this article, you will learn about \u201cmap\u201d in the C++ programming language in detail. What is a map? Why we use a map? How to create a map? How to use a map in C++?","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/","og_locale":"en_US","og_type":"article","og_title":"Map in C++","og_description":"In this article, you will learn about \u201cmap\u201d in the C++ programming language in detail. What is a map? Why we use a map? How to create a map? How to use a map in C++?","og_url":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2021-04-12T09:04:41+00:00","article_modified_time":"2024-09-03T05:38:53+00:00","og_image":[{"width":1000,"height":667,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Map in C++","datePublished":"2021-04-12T09:04:41+00:00","dateModified":"2024-09-03T05:38:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/"},"wordCount":2048,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg","articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/","url":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/","name":"Map in C++","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg","datePublished":"2021-04-12T09:04:41+00:00","dateModified":"2024-09-03T05:38:53+00:00","description":"In this article, you will learn about \u201cmap\u201d in the C++ programming language in detail. What is a map? Why we use a map? How to create a map? How to use a map in C++?","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/map-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Map in C++"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg",1000,667,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg",1000,667,false],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg",1000,667,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487.jpg",1000,667,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487-640x667.jpg",640,667,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_528261487-150x100.jpg",150,100,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"In this article, you will learn about \u201cmap\u201d in the C++ programming language in detail. What is a map?&nbsp; Why we use a map? How to create a map? How to use a map in C++?&nbsp; What is \u201cMAP\u201d? The map is a library of standard template library (STL). Now you think that what is&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/30282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=30282"}],"version-history":[{"count":4,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/30282\/revisions"}],"predecessor-version":[{"id":111516,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/30282\/revisions\/111516"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/30295"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=30282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=30282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=30282"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=30282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}