How to get the index number of an element into an array?

I tried to use find() function but it returns the element not the position.

1
2
3
4
5
int ar[5]={1,2,3,4,3};

int *l;
l=find(ar, ar+5, 3);
cout<<*l<<endl;


is there any function that returns the position?
Last edited on
your information is not detail...
what result you expected for...?
Yes. find returns an iterator to that position.
To get the index, subtract the value returned from the beginning of the array.
1
2
l = find(ar, ar + 5, 3);
cout<<"position is "<<l-ar<<enld;
Topic archived. No new replies allowed.