im trying to locate the position of the minimum value in a vector, using STL find algorithm (and the min_element algorithm), but instead of returning the postion, its just giving me the value. E.g, if the minimum value is it, is position will be returned as 8 etc. What am I doing wrong here?
int value = *min_element(v2.begin(), v2.end()); cout << 'min value at position ' << *find(v2.begin(), v2.end(), value);
min_elementalready gives you the iterator, no need to invokefind(additionally, it’s inefficient because it’s twice the work). Usedistanceor the-operator: