lambda表达式初步
生活随笔
收集整理的這篇文章主要介紹了
lambda表达式初步
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
// Lambda_test20140801.cpp : 定義控制臺應(yīng)用程序的入口點。
//#include "stdafx.h"
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;int main()
{//創(chuàng)建一個包含10個元素的集合對象vector<int> v;for (int i = 0; i < 10; ++i){v.push_back(i);}//使用for_each 語句和lambda表達式來實現(xiàn)對偶元素的計數(shù)int evenCount = 0;for_each(v.begin(),v.end(),[&evenCount](int n){cout<<n;if (n % 2 == 0){cout<<" is even"<<endl;//increment the counterevenCount++;}else{cout<<" is odd"<<endl;}});//將偶元素個數(shù)打印出來cout<<"There are "<<evenCount<<" even numbers in the vector"<<endl;getchar();return 0;
}
轉(zhuǎn)載于:https://www.cnblogs.com/wuyida/p/6301451.html
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的lambda表达式初步的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ubuntu版本介绍
- 下一篇: 特权同学笔记-榨干FPGA片上存储资源