how to find the index of an element in a vector c++

C++
vector<int> arr = { 6, 3, 5, 2, 8 };
vector<int>::iterator itr = std::find(arr.begin(), arr.end(), elem);

if (itr != end(arr)) {
	cout << "Element " << elem << " is present at index " << distance(arr, itr) << " in the given array";
}
else {
	cout << "Element is not present in the given array";
}#include <iostream>
#include <vector>
#include <algorithm>
 
int main()
{
    std::vector<int> v = { 7, 3, 6, 2, 6 };
    int key = 6;
 
    std::vector<int>::iterator itr = std::find(v.begin(), v.end(), key);
 
    if (itr != v.cend()) {
        std::cout << "Element present at index " <<
                    std::distance(v.begin(), itr);
    }
    else {
        std::cout << "Element not found";
    }
 
    return 0;
}

Source

Also in C++: