find_if与数据结构的向量 [英] find_if with vector of data structures
问题描述
如何将find_if与数据结构向量一起使用?
我有这样的东西:
struct Record {
int ID;
int Data1;
int Data2;
};
vector< Record> MyRecords;
我想根据ID找到记录。我应该使用find_if吗?我该怎么办?我知道如何使用简单数据类型的find_if但不知道如何编写在这种情况下检查条件的函数。
非常感谢您的回答。
How can I use find_if with vector of data structures?
I have something like this:
struct Record{
int ID;
int Data1;
int Data2;
};
vector<Record> MyRecords;
I would like to find a record based on ID. Should I use find_if and how can I do it? I know how to use find_if with simple data types but do not know how to write function that checks the condition in this case.
Thank you a lot for your answer.
推荐答案
如何将find_if与数据结构向量一起使用?
我有类似这样的事情:
struct Record {
int ID;
int Data1;
int Data2;
};
vector< Record> MyRecords;
我想根据ID找到记录。我应该使用find_if吗?我该怎么办?我知道如何使用简单数据类型的find_if但不知道如何编写在这种情况下检查条件的函数。
非常感谢您的回答。
How can I use find_if with vector of data structures?
I have something like this:
struct Record{
int ID;
int Data1;
int Data2;
};
vector<Record> MyRecords;
I would like to find a record based on ID. Should I use find_if and how can I do it? I know how to use find_if with simple data types but do not know how to write function that checks the condition in this case.
Thank you a lot for your answer.
你想做什么样的比较?
What kind of comparisons do you want to make?
什么你想做什么比较?
What kind of comparisons do you want to make?
我想基于给定的id找到记录,所以Record.ID == GivenID。
I would like to find record based on given id, so Record.ID==GivenID.
我想根据给定的id找到记录,所以Record.ID == GivenID。
I would like to find record based on given id, so Record.ID==GivenID.
编写自己的函数可能更好:
Maybe it''s better to write your own function:
这篇关于find_if与数据结构的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!