Position in Vector using STL

后端 未结 3 801
独厮守ぢ
独厮守ぢ 2021-02-04 04:22

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 givin

3条回答
  •  既然无缘
    2021-02-04 05:20

    min_element already gives you the iterator, no need to invoke find (additionally, it's inefficient because it's twice the work). Use distance or the - operator:

    cout << "min value at " << min_element(v2.begin(), v2.end()) - v2.begin();
    

提交回复
热议问题