关于#向量与结构体#的问题,如何解决?(语言-c++)

我在vector中使用了结构体

struct stu {
    string name;
    int score;
};


//在一个函数中
vectordata;


stu是有两个值的
现在我想通过搜索name对score进行修改
我的想法是遍历整个data(data有初值),将其中的name与输入的值进行比较然后输出对应的score
但是我不知道怎么写

用迭代器遍历啊

vector<stu>::iterator it = data.begin();
    for(; it != data.end(); ++it)
    {
       if(it->name == name)
        cout<<it->score<<" ";
    }

也可以重载==运算符,用find函数

#include<algorithm>//find函数所在头文件
//重载== 
bool operator ==(const struct stu&st,const string name){
    return st.name==name;
}
//在data中查找name对应的stu,并将其分数改为score 
bool modify(vector<stu>&data, string name,int score){
    vector<stu>::iterator it=find(data.begin(),data.end(),name);
    if(it!=data.end()){
        it->score=score;
        return true;
    }else{
        return false;
    }
}