Get the maximum element in a sequence with algorithm max_element - C++ STL Algorithm

C++ examples for STL Algorithm:max_element

Description

Get the maximum element in a sequence with algorithm max_element

Demo Code

#include <iostream> 
#include <algorithm> // algorithm definitions 
#include <numeric> // accumulate is defined here 
#include <vector> 
#include <iterator> 
using namespace std; 

int main() //from w w w.  j a va 2 s  .c  o  m
{ 
   const int SIZE = 10; 
   int a1[ SIZE ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 
   vector< int > v( a1, a1 + SIZE ); // copy of a1 
   ostream_iterator< int > output( cout, " " ); 

   // locate maximum element in v2 
   cout << "\nMaximum element in Vector v2 is: " 
       << *( max_element( v.begin(), v.end() ) ); 

}

Result


Related Tutorials