基础知识,直接看代码:
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> a = { 2,4,6,7,1,0,8,9,6,3,2 };
auto maxPosition = std::max_element(a.begin(), a.end()); // 最小值min_element
std::cout << *maxPosition << " at the position of " << maxPosition - a.begin() << std::endl;
return 0;
}
输出:
9 at the position of 7