#include <iostream>
#include <map>
#include <queue>
using namespace std;
int main()
{
map<int,string> student;
student.insert(pair<int,string>(2,"li"));
student.insert(pair<int,string>(1,"wang"));
student.insert(pair<int,string>(3,"sun"));
for(auto &v : student)
cout<<v.first<<endl;
return 0;
}
输出:
![](https://img-blog.csdnimg.cn/2022010613553079314.png)
由此可见,遍历的时候是按key值进行遍历。
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
int main()
{
vector<int> q;
q.push_back(3);
q.push_back(1);
q.push_back(2);
for(auto &v : q)
cout<<v<<endl;
vector<int>w[3];
w[0].push_back(3);
w[0].push_back(1);
w[0].push_back(2);
for(auto &v : w[0])
cout<<v<<endl;
return 0;
}
![]()