1 #include<iostream> 2 #include<vector> 3 4 bool GT6(const int &s){ 5 return s>=6; 6 } 7 int main(){ 8 int a[]={0,1,2,3,4,5,6,7,8,9}; 9 std::vector<int>vec(a,a+10); 10 std::cout<<count_if(vec.begin(),vec.end(),GT6)<<std::endl; 11 return 0; 12 }
#include<iostream> #include<vector> class GT_cls{ public: GT_cls(int val=0):i(val){} bool operator()(const int &s){ return s>=i; } private: int i; }; int main(){ int a[]={0,1,2,3,4,5,6,7,8,9}; std::vector<int>vec(a,a+10); std::cout<<count_if(vec.begin(),vec.end(),GT_cls(6) )<<std::endl; return 0; }
时间: 2024-10-04 00:08:15