Erase a found pair from map : map erase « map multimap « C++ Tutorial






#include <iostream>
#include <map>
#include <string>

using namespace std;

int main( ) {

   map<string, string> strMap;

   strMap["Monday"]    = "1";
   strMap["Tuesday"]   = "2";
   strMap["Wednesday"] = "3";
   strMap["Thursday"]  = "4";
   strMap["Friday"]    = "5";
   strMap["Saturday"]  = "6";
   strMap.insert(pair<string, string>("Sunday", "7"));

   strMap.erase(strMap.find("Tuesday"));

   for (map<string, string>::iterator p = strMap.begin( );
      p != strMap.end( ); ++p ) {
         cout << "English: " << p->first<< ", #: " << p->second << endl;
   }

   cout << endl;

}
English: Friday, #: 5
English: Monday, #: 1
English: Saturday, #: 6
English: Sunday, #: 7
English: Thursday, #: 4
English: Wednesday, #: 3








23.4.map erase
23.4.1.Remove an entry from a map
23.4.2.clear the content of a map with erase(Map.begin(), Map.end());
23.4.3.clear the content of a map with clear() function
23.4.4.Erase a found pair from map