C++ 标准库 std::find 查找
参见:https://en.cppreference.com/w/cpp/algorithm/find
查找指定字符/数字等。
#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 }