参见:https://en.cppreference.com/w/cpp/algorithm/find
std::npos 表示 size_t 的最大值,常用于对查找结果成功与否的判断。
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
int main()
{
int n1 = 3;
int n2 = 5;
std::vector<int> v{0, 1, 2, 3, 4};
auto result1 = std::find(std::begin(v), std::end(v), n1);
if (result1 == std::npos) {
std::cout << "no found " << n1 << '\n';
}
return 0
}