C++11 for循环

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循环)