我有两个stl地图map<int,int> ,我想比较它们..所以这里是代码..
map <int, int> a,b;
insert into a and b;
map<int,int>::iterator i;
for(i=a.begin();i!=a.end();i++){
if(what should be here?)
then cout << (*i).first << " also present in b" << endl;
}
Run Code Online (Sandbox Code Playgroud)
我希望像(b [(*i).first])之类的东西存在?
使用map::find如:
for(i=a.begin(); i!=a.end(); i++)
{
if( b.find(i->first) != b.end() )
std::cout << (*i).first << " also present in b" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
注意i->first并且(*i).first是相同的.
| 归档时间: |
|
| 查看次数: |
1379 次 |
| 最近记录: |