下面是一个示例代码: #include <iostream> #include <vector> #include <algorithm> int main() { std::vector<int> vec = {1, 2, 3, 4, 5}; int target = 3; auto it = std::find(vec.begin(), vec.end(), target); if (it != vec.end()) { std::cout << "Element found at inde...
要使用vector查找指定元素,可以使用std::find函数。具体操作如下: #include <iostream> #include <vector> #include <algorithm> int main() { std::vector<int> vec = {1, 2, 3, 4, 5}; int target = 3; auto it = std::find(vec.begin(), vec.end(), target); if (it != vec.end()) ...