#include<iostream> #include<vector> #include<algorithm> using namespace std; class Student{ public: int No; string strName; int grade; Student(int No,string strName,int grade):No(No),strName(strName),grade(grade){}; bool operator ==(int grade){ return this->grade==grade; } }; int main(){ vector<Student>v; Student s1(1000,"张三",80); Student s2(1001,"李四",85); Student s3(1002,"王五",80); Student s4(1003,"赵六",80); v.push_back(s1); v.push_back(s2); v.push_back(s3); v.push_back(s4); int nCount; nCount=count(v.begin(),v.end(),80); cout<<nCount<<endl; }
template <class InputIterator, class T> typename iterator_traits<InputIterator>::difference_type count ( ForwardIterator first, ForwardIterator last, const T& value );
count用法
最新推荐文章于 2022-12-03 20:39:36 发布