问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
vector元素最大值的值和位置
vector元素最大值的值和位置
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
vector<int> a = { 2,4,6,7,1,0,8,9,6,3,2 };
int maxPosition = max_element(a.begin(), a.end());
cout << *maxPosition << " at the postion of " << maxPosition - a.begin() <<endl;
//cout << a[maxPosition - a.begin()] << " at the postion of " << distance(a.begin(), maxPosition) << endl;
return 0;
}