我在vector中使用了结构体
struct stu {
string name;
int score;
};
//在一个函数中
vector<stu>data;
stu是有两个值的
现在我想通过搜索name对score进行修改
我的想法是遍历整个data(data有初值),将其中的name与输入的值进行比较然后输出对应的score
但是我不知道怎么写
我在vector中使用了结构体
struct stu {
string name;
int score;
};
//在一个函数中
vector<stu>data;
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<<" ";
}