Monday, June 10, 2013

C++ map::find() and map::operator[]

// map::find
#include <iostream>
#include <map>

int main ()
{
  std::map<char,int> mymap;
  std::map<char,int>::iterator it; //when using find

  mymap['a']=50;
  mymap['b']=100;
  mymap['c']=150;
  mymap['d']=200;

  it=mymap.find('b');
  mymap.erase (it);
  mymap.erase (mymap.find('d'));

  // print content:
  std::cout << "elements in mymap:" << '\n';
  std::cout << "a => " << mymap.find('a')->second << '\n';
  std::cout << "c => " << mymap.find('c')->second << '\n';

  return 0;
}

 map::iterator itr = breakdownMap.find(stkAssignment->getBreakdownN());
    if(itr==breakdownMap.end())
      continue;
    DBYardCntrBrkDn* yardCntrBrkDn = itr->second;
done

No comments:

Post a Comment