Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Set vs Map in C++ STL

#include<iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   map<char, int> m;                     //initialize a map
   map<char, int>::iterator iter;       //initializing a map as iterator
   m.insert (pair<char, int>('a', 10)); //inserting values to the map
   m.insert (pair<char, int>('b', 20));

   cout << "Elements in map:\n";
   for (iter=m.begin();iter!=m.end();iter++)
   cout << "[ " << iter->first << ", "<< iter->second << "]\n"; //printing the values of the map
   return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.