C++ map insert

Introduction

To insert into a map, we can use the.insert() member function:

#include <iostream> 
#include <map> 

int main() /*from   www.j  av  a  2  s  .c  o  m*/
{ 
    std::map<int, char> mymap = { {1, 'a'}, {2, 'b'}, {3,'z'} }; 
    mymap.insert({ 20, 'c' }); 

    for (auto el : mymap) 
    { 
        std::cout << el.first << ' ' << el.second << '\n'; 
    } 
} 



PreviousNext

Related