index of max element in vector c++ code example

Example 1: max of a vector c++

cout<<*max_element(a.begin(), a.end())<<endl;

Example 2: max element in vector c++

auto max = *max_element(vector.begin(), vector.end());

Example 3: get min and max element index from vector c++

int maxElementIndex = std::max_element(v.begin(),v.end()) - v.begin();
int maxElement = *std::max_element(v.begin(), v.end());

int minElementIndex = std::min_element(v.begin(),v.end()) - v.begin();
int minElement = *std::min_element(v.begin(), v.end());

Tags:

Cpp Example