您的位置:首页 > 编程语言 > C语言/C++

c++11,for,for each,std::for_each的应用

2015-12-04 19:36 573 查看
// 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>


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++11 for循环