#include"algorithm"
vector<int> initial_value = { 1,2,3,8,55,6,22,10,6 };
auto ibeg = initial_value.begin(), ied = initial_value.end();
// 方式 1 :找出需要的值
vector<int>::iterator result =std::find(ibeg, ied, 6);
// 方式 2 找出需要的值
auto result11 = std::find(ibeg, ied, 55);
/* 方式 1 和 方式 2 等价 选用一种即可*/
// 找到需要的元素,输出,否则 打印 not find
if (result11 == ied)
{
qDebug() << "not find" << endl;
}
else
{
qDebug() << *result << endl;
}

本文展示了一种在C++中使用STL库中的find函数查找特定元素的方法。通过具体的代码示例,演示了如何在vector容器中搜索指定数值,并处理未找到目标值的情况。

被折叠的 条评论
为什么被折叠?



