vector的find方法
时间: 2024-05-17 10:16:15 浏览: 77
vector应用方法
vector的find方法存在于<algorithm>头文件中。你可以使用find函数来查找vector中是否存在某个特定的元素。下面是一个示例代码:
```cpp
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
vector<int> L;
L.push_back(1);
L.push_back(2);
L.push_back(3);
vector<int>::iterator it = find(L.begin(), L.end(), 3);
if(it == L.end())
cout << "NO" << endl;
else
cout << "YES" << endl;
}
```
在这个例子中,我们定义了一个vector L,然后使用find函数来查找值为3的元素。如果找到了,输出YES,否则输出NO。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [vector的find用法](https://blog.csdn.net/wcxyky/article/details/88543873)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [vector中find 的用法](https://blog.csdn.net/KUAILE123/article/details/11103373)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文