// cpp11exercise.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
void hello(int a)
{
std::cout<<a<<std::endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int> vv ;
vv.push_back(2);
vv.push_back(2);
for(auto a : vv)
{
hello(a);
}
int a[] = {3,3,3};
for each (auto var in vv)
{
hello(var);
}
std::for_each(vv.begin(),vv.end(),hello);
std::for_each(a,a+1,hello);
return 0;
}
其中,std::for_each需要头文件<pre name="code" class="cpp">#include <algorithm>