标签:style blog color os io 使用 div cti sp
19.18编写一个函数,使用count_if统计在给定的vector中有多少个空string。
#include<algorithm> #include<string> #include<iostream> #include<vector> #include<functional> using namespace std; int main() { vector<string> svec={"fhhd","fdf","","hafh","",""}; function<bool (const string&)> fcn=&string::empty; cout<<find_if(svec.begin(),svec.end(),fcn)-svec.begin()<<endl; cout<<find_if(svec.begin(),svec.end(),mem_fn(&string::empty))-svec.begin()<<endl; cout<<find_if(svec.begin(),svec.end(),bind(&string::empty,std::placeholders::_1))-svec.begin()<<endl; cout<<count_if(svec.begin(),svec.end(),fcn)<<endl; cout<<count_if(svec.begin(),svec.end(),mem_fn(&string::empty))<<endl; cout<<count_if(svec.begin(),svec.end(),bind(&string::empty,std::placeholders::_1))<<endl; }
标签:style blog color os io 使用 div cti sp
原文地址:http://www.cnblogs.com/wuchanming/p/3956946.html