We have one map which key and value both are int type. We have to search a particular value in the map and collect those key in one vector. Code snapshot is like
map<int,int>m;
map<int,int>::iterator itr;
vector<int> v;
m.insert(make_pair<int,int>(1,2));
m.insert(make_pair<int,int>(2,2));
m.insert(make_pair<int,int>(3,2));
m.insert(make_pair<int,int>(4,4));
m.insert(make_pair<int,int>(5,5));
现行法典类似:
for ( itr = m.begin(); itr != m.end(); ++itr )
{
if ((*itr).second == 2 )
v.push_back((*itr).first )
}
我们愿优化这项工作。 我们如何能够使用STL算法。