C++ min_element()

Introduction

To find the smallest element in the container, we use the std::min_element function, which returns an iterator to the min element in the container or a range:

#include <iostream> 
#include <vector> 
#include <algorithm> 

int main() /*from   w ww  .java2 s  .  c  o  m*/
{ 
    std::vector<int> v = { 1, 2, 3, 4, 5 }; 
    auto it = std::min_element(std::begin(v), std::end(v)); 
    std::cout << "The min element in the vector is: " << *it; 
} 



PreviousNext

Related