Use max_element to get the maximum value : max_element « STL Algorithms Min Max « C++ Tutorial






#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main(){
   const float a[] = { 13.4, 27.6, 15.5, 44.3, 51.2, 30.2, 18.0 };
   vector<float> data( a,a + sizeof( a ) / sizeof( a[0] ) );

   float data_min = *min_element( data.begin(), data.end() );
   float data_max = *max_element( data.begin(), data.end() );

   cout << data_max;
}








29.2.max_element
29.2.1.Find and print maximum elements in a vector
29.2.2.Use max_element to get the maximum element in a container
29.2.3.Use max_element to get the maximum value
29.2.4.Use max_element with criteria function