map这种数据结构

定义:

map<int ,char>newmap;

迭代器:std::map<int,cahr>::iterator it=newmap.begin()//newmap.end();

newmap.empty();

newmap.size();

newmap.insert(pair<int,char>(1,'c'));

newmap.insert(newmap.begin(),pair<int,cahr>(1,'c'))

// third insert function version (range insertion):

  std::map<char,int> anothermap;
  anothermap.insert(mymap.begin(),mymap.find('c'));
输出map的值:
std::cout << "anothermap contains:
";
  for (it=anothermap.begin(); it!=anothermap.end(); ++it)
    std::cout << it->first << " => " << it->second << '
';
删除erase:
  it=mymap.find('b');
  mymap.erase (it);                   // erasing by iterator

  mymap.erase ('c');                  // erasing by key

  it=mymap.find ('e');
  mymap.erase ( it, mymap.end() );    // erasing by range

swap:
map1.swap(map2);交换两个map之间的值;
find(key)
it = mymap.find('b'); //返回的是查找到的元素的迭代器位置;
 


原文地址:https://www.cnblogs.com/mmziscoming/p/5757273.html