遍历容器

  1. 利用迭代器  

 

for(auto it=a.begin();a!=a.end();it++){

  cout<<*it<<endl;  

}

 

  1. for_each

void func(double x){

cout<<x<<endl;

}

vector<double>a;

for_each(a.begin(),a.end(),func)

  1. 新用法

unordered_map<char,int>s;

for(auto it:s){

  cout<<it.second;

}

String s;

for(char ch:s){}

unordered_map(char,int)map;

for(auto a:map){}

 

posted @ 2023-04-06 10:22  iu本u  阅读(16)  评论(0)    收藏  举报