需要在结构体 定义时 添加operator
#include <iostream>
#include <map>
#include <vector>
#include <fstream>
#include <assert.h>
#include <algorithm>
using namespace std;
struct g
{
int a;
string b;
bool operator == (const g &e){
return (this->a == e.a) && (this->b == e.b);
}
};
int main()
{
g new_g;
new_g.a=1;
new_g.b="1";
vector<g> vecc;
vecc.push_back(new_g);
g find_g;
find_g.a=1;
find_g.b="1";
auto iter=find(vecc.begin(),vecc.end(),find_g);
if (iter!=vecc.end())
{
cout<<"1"<<endl;
}
}