标签:lse 数据 com turn 相等 需要 定义 span ant
STL的find,find_if函数提供了一种对数组、STL容器进行查找的方法。使用该函数,需 #include <algorithm>
我们查找一个list中的数据,通常用find(),例如:
文章来源:http://www.codelast.com/
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
using namespace std;int main(){list<int> lst;lst.push_back(10);lst.push_back(20);lst.push_back(30);list<int>::iterator it = find(lst.begin(), lst.end(), 10); // 查找list中是否有元素“10”if (it != lst.end()) // 找到了{// do something}else // 没找到{// do something}return 0;} |
那么,如果容器里的元素是一个类呢?例如,有list<CPerson> ,其中CPerson类定义如下:
|
1
2
3
4
5
6
7
|
class CPerson{public:CPerson(void); ~CPerson(void);public:int age; // 年龄}; |
|
1
|
bool operator==(const CPerson &rhs) const; |
| 再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net |
标签:lse 数据 com turn 相等 需要 定义 span ant
原文地址:https://www.cnblogs.com/sjwudhwhhw/p/10442907.html