C++ for_each函数\for_each模板
2013-06-01 09:46
253 查看
for_each()函数
void for_each( int (&int_ref)[10] )
{
for( inti=0; i<10; ++i )
cout<< int_ref[i]<< endl;
}
int main( int argc, char* argv[] )
{
intint_array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
for_each(int_array );
return0;
}
for_each模板
Function for_each(InputIterator first, InputIterator last, Functionf)
{
while(beg != end)
f(*beg++);
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void my_each( int i)
{
cout<< " "<< i <<endl;
}
int main( int argc, char* argv[] )
{
std::vector<int> myvector;
myvector.push_back(10);
myvector.push_back(20);
myvector.push_back(30);
for_each(myvector.begin(), myvector.end(), my_each);
return0;
}
更多详情参考:http://blog.csdn.net/yingevil/article/details/6745793
void for_each( int (&int_ref)[10] )
{
for( inti=0; i<10; ++i )
cout<< int_ref[i]<< endl;
}
int main( int argc, char* argv[] )
{
intint_array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
for_each(int_array );
return0;
}
for_each模板
Function for_each(InputIterator first, InputIterator last, Functionf)
{
while(beg != end)
f(*beg++);
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void my_each( int i)
{
cout<< " "<< i <<endl;
}
int main( int argc, char* argv[] )
{
std::vector<int> myvector;
myvector.push_back(10);
myvector.push_back(20);
myvector.push_back(30);
for_each(myvector.begin(), myvector.end(), my_each);
return0;
}
更多详情参考:http://blog.csdn.net/yingevil/article/details/6745793
相关文章推荐
- C++之STL(五):非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)
- 代码简洁之道:C++ 11 之auto+ for_each + lamda表达式
- c++for_each的用法
- 代码简洁之道:C++ 11 之auto+ for_each + lamda表达式
- C++ 11标准新增加了Lambda表达式、for_each语法,修改了auto
- 多想追求简洁的极致,但是无奈的学习C++中for_each的应用
- 【C++ STL学习之六】STL算法之for_each
- C++ STL 学习 :for_each与仿函数(functor)
- Effective Standard C++ Library: for_each() vs. transform()
- 现代C++ 基于范围的for和for_each语句
- C++中transform和for_each的实现
- C++新特性之lambda表达式在for_each循环中的使用及for循环新写法
- C++ STL 中有关于for_each() 和 transform() 算法
- 代码简洁之道:C++ 11 之auto+ for_each + lamda表达式
- 现代C++ 基于范围的for和for_each语句
- C++ for_each() 和 transform() 的比较
- c++11,for_each的并行化,改写模板
- C++ 11 标准 新增的Lambda表达式、for_each语法,改变了auto关键字的意义
- 从零开始学C++之STL(五):非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)
- 在C++中实现foreach循环,比for_each更简洁!