遍历vector
int main()
{
vector <int> vec;
//vec.push_back();
for(auto &p : vec)//这里这样可以实现从第一个元素开始遍历输出vec
count << p << endl;
/*等价于
for(int i = 0; i < vec.size(); ++i)
{
count << vec[i] << endl;
}
*/
return 0;
}
遍历map
#include <iostream>
#include <map>
#include <queue>
using namespace std;
int main()
{
map<int, string> mp;
mp.insert(pair<int,string>(2,"hello"));
mp.insert(pair<int,string>(1,"miaomiaomiao"));
mp.insert(pair<int,string>(3,"world"));
for(auto &p : mp)
cout << p.first << endl;
return 0;
}
输出是1 2 3
可见遍历的时候是按key值进行遍历
参考来源
博客
https://blog.csdn.net/sdnulixianrui/article/details/78627544