#include<iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>
class Person
{
public:
Person(string name, int age)
{
this->m_name = name;
this->m_age = age;
}
bool operator==(const Person &p)
{
if (this->m_age == p.m_age )
{
return true;
}
else
{
return false;
}
}
string m_name;
int m_age;
};
void test()
{
vector<int> v;
v.push_back(10);
v.push_back(20);
v.push_back(10);
v.push_back(30);
v.push_back(10);
int num = count(v.begin(), v.end(), 10);
cout << num << endl;
vector<Person> v1;
Person p1("aaa", 10);
Person p2("bbb", 20);
Person p3("ccc", 30);
Person p4("ddd", 10);
Person p5("eee", 10);
int num2 = count(v.begin(), v.end(), 10);
cout << num2 << endl;
}
int main()
{
test();
}
count统计容器中相同元素的数量
最新推荐文章于 2023-03-12 16:44:59 发布