Source of min_element1a.cpp


  1: //min_element1a.cpp

  3: #include <iostream>
  4: #include <vector>
  5: #include <algorithm>
  6: using namespace std;

  8: int main()
  9: {
 10:     cout << "\nThis program illustrates the use of the STL min_element() "
 11:             "algorithm\n(default version) to find the minimum value in "
 12:             "a vector of integers.";
 13:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 15:     int a[] = {8, 6, 10, 2, 4};
 16:     vector<int> v(a, a+5);

 18:     cout << "\nHere are the integer values in the vector:\n";
 19:     for (vector<int>::size_type i=0; i<v.size(); i++)
 20:         cout << v.at(i) << " ";
 21:     cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');

 23:     cout << "\nThe minimum value in the vector is "
 24:         << *min_element(v.begin(), v.end()) << ".";
 25:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 26: }