我很困惑哪个更有效率?
由于我们可以直接访问地图,为什么我们需要使用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;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!:)