void func2(int n){std::cout << n << std::endl; }
std::vectorarr; arr.push_back(1); arr.push_back(2);
std::for_each(arr.begin(), arr.end(), func2);
或者:
for(auto n : arr ){std::cout << n << std::endl;} for(auto& n:arr)
void func2(int n){std::cout << n << std::endl; }
std::vectorarr; arr.push_back(1); arr.push_back(2);
std::for_each(arr.begin(), arr.end(), func2);
或者:
for(auto n : arr ){std::cout << n << std::endl;} for(auto& n:arr)
本文标题:C++11 for循环
本文链接:https://www.haomeiwen.com/subject/apfucxtx.html
网友评论