【发布时间】:2012-05-14 11:04:23
【问题描述】:
我很困惑哪个更有效?
既然可以直接访问map,为什么还要使用find呢?
我只需要知道哪种方式更有效。
#include <iostream>
#include <map>
using namespace std;
int main ()
{
map<char,int> mymap;
map<char,int>::iterator it;
mymap['a']=50;
mymap['b']=100;
mymap['c']=150;
mymap['d']=200;
//one way
it=mymap.find('b');
cout << (*it).second <<endl;
//another way
cout << mymap['b'] <<endl;
return 0;
}
提前致谢! :)
【问题讨论】:
标签: c++ stl map upperbound