c++ find element in vector
auto it = find(vec.begin(),vec,end(), item)!
if(it != vec.end()){
int index = it - vec.begin();
}
c++ find element in vector
auto it = find(vec.begin(),vec,end(), item)!
if(it != vec.end()){
int index = it - vec.begin();
}
C++ array find method
#include <iostream>
#include <algorithm>
#include <array>
using namespace std;
int main() {
array<int, 5> arrayfind{ 3,4,1,2,5 };
int Finding = 2;//an element to find
bool Founded;
Founded = binary_search(arrayfind.begin(), arrayfind.end(), Finding);
//if the element that you're looking for is in the array,
//bool Founded will be true
if (Founded == true) {
cout << Finding << " Is in the array!";
}
else {
cout << Finding << " Is not in the array!";
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us