Horje
c++ find index of an element Code Example
get index of value 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";
}
c++ find index of an element
#include <iostream>
#include <vector> 
#include <iterator> 
#include <algorithm>  
using namespace std;

int main()
{
    vector<int> v = {1,2,3,4,6,4,5};
    // Get index of element from iterator
    int index = distance(v.begin(), find(v.begin(), v.end(), 4));
    cout << index;
}




Cpp

Related
cpp #include "" <> Code Example cpp #include "" <> Code Example
I2c scanner arduino Code Example I2c scanner arduino Code Example
c++ double to string Code Example c++ double to string Code Example
powershell get uptime remote computer Code Example powershell get uptime remote computer Code Example
remove element from vector c++ Code Example remove element from vector c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7