how to find index of a vector in c++

[ad_1]

how to find index of a vector in c++
#include 
#include 
#include 

using namespace std;

int main() {
	vector v = { 7, 3, 6, 2, 6 };
	int key = 6;
	vector::iterator itr = find(v.begin(), v.end(), key);
	int index = distance(v.begin(), itr);
	cout << index << endl;

	return 0;
}

[ad_2]

Please follow and like us:
Content Protection by DMCA.com