编辑代码

#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
#include <string>

void test01() {
	vector<int> v;
	v.push_back(1);
	v.push_back(2);
	v.push_back(4);
	v.push_back(5);
	v.push_back(3);
	v.push_back(4);
	v.push_back(4);

	int num = count(v.begin(), v.end(), 4);

	cout << "4的个数为: " << num << endl;
}

class Person {
public:
    Person(string name, int age) {
        this->m_Name = name;
        this->m_Age = age;
    }

    bool operator==(const Person &p) {
        // if (this->m_Name == p.m_Name && this->m_Age == p.m_Age) {
        if (this->m_Age == p.m_Age) {
            return true;
        } else {
            return false;
        }
    }
    string m_Name;
    int m_Age;
};

void test02() {
    vector<Person> v;

    Person p1("lucy", 21);
    Person p2("chainsawman", 17);
    Person p3("mkm", 23);
    Person p4("Aki", 19);
    Person p5("Power", 17);
    Person p6("Reze", 17);

    v.push_back(p1);
    v.push_back(p2);
    v.push_back(p3);
    v.push_back(p4);
    v.push_back(p5);
    v.push_back(p6);

    int num = count(v.begin(), v.end(), p2);
    cout << "p2的个数为: " << num << endl;

}

int main() {
    test01();
    test02();
	return 0;
}