The C + + Lab class requires a For Each loop to implement the output of the associated container map, beginning with the full-scale. After a long time to find the information to sort out the following:
One of the new features of C++11 is Java-like for Each loop:
1map<int,string>m;2 //13 for(Auto &v:m)4 {5cout<<v.first<<" "<<v.second<<Endl;6 }7 8 //2-LAMDA expression9For_each (M.begin (), M.end (), [] (map<int,string>:: Reference a) {Tencout<<a.first<<" "<<a.second<<Endl; One }); A - //3 For_each - voidFun (map<int,string>::reference a)//don't reference less, or you will get an error. the { -cout<<a.first<<" "<<a.second<<Endl; - } -For_each (M.begin (), M.end (), fun);
There is also a way to define macros:
1 //definition2 #defineforeach (Container,it)3 for(typeof((container). Begin ()) it = (container). Begin (); it!= (container). end (); + +it)4 //Output5 foreach(m,it)6 {7cout<<it->first<<","<<it->second<<Endl;8}
New features of C + + For-each