基础知识,直接看代码:
#include#include #include int main(){ std::vector 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
参考:C++ 求vector的最大值最小值和平均数



