关闭

几个lamda表达式

215人阅读 评论(0) 收藏 举报
分类:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int main(){
	
	char* a[]={"abc","asdaf","afsdagherws","abrrc","qweqweqweqweqwe","ab"};
	vector<char*>v(a,a+6);
	sort(v.begin(),v.end(),[](char* a,char* b){return a<b;});//按地址大小顺序排序
	for_each(v.begin(),v.end(),[](char* &a){cout<<a<<" ";});
	cout<<endl;


	int ab[2000];
	for(int i=0;i<2000;i++) ab[i]=i+1;
	vector<int>vv(ab,ab+2000);
	cout<<count_if(vv.begin(),vv.end(),[](const int&a){return !(a%11);});//被11整数的数目
	cout<<endl;


	string str[]={"pooh","pooh","pooh","pooh","asd","asdasaf","asdasd"};
	vector<string>v3(str,str+7);
	cout<<*find_if(v3.begin(),v3.end(),[](const string &a){return a!="pooh";});
	cout<<endl;

	vector<int>v4(7,2);
	for_each(v4.begin(),v4.end(),[](int& a){a=multiplies<int>()(a,2);});
	for_each(v4.begin(),v4.end(),[](const int& b){cout<<b<<" ";});

	system("pause");
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:122431次
    • 积分:4477
    • 等级:
    • 排名:第7004名
    • 原创:266篇
    • 转载:466篇
    • 译文:0篇
    • 评论:3条
    文章分类