1: //min1a.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() " 11: "algorithm (default version)\nto find the minimum of two " 12: "integer literal values, the minimum of two integer\nvalues " 13: "stored in simple integer variables, and (in two different " 14: "ways) the\nminimum of two integer values stored in a vector " 15: "of integers."; 16: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 18: cout << "\nFirst, we find the mminimum of two integer " 19: "literal values.\n"; 20: cout << "min(12, -3) = " << min(12, -3); 21: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 23: int first = 7; 24: int second = 10; 25: cout << "\nNext, we find the minimum of two integer " 26: "\nvalues stored in simple integer variables."; 27: cout << "\nfirst = " << first << " second = " << second << endl; 28: cout << "min(first, second) = " << min(first, second); 29: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 31: int a[] = {2, 6, 10, 8, 4}; 32: vector<int> v(a, a+5); 34: cout << "\nHere are the integer values in the vector:\n"; 35: for (vector<int>::size_type i=0; i<v.size(); i++) 36: cout << v.at(i) << " "; 37: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 39: cout << "\nNow we find the minimum of the first and last values " 40: "\nstored in the vector of integers using one approach."; 41: cout << "\nmin(v.at(0), v.at(4)) = " << min(v.at(0), v.at(4)); 42: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 44: cout << "\nFinally, we find the minimum of the first and last values " 45: "\nstored in the vector of integers using a second approach."; 46: cout << "\nmin(*v.begin(), *(v.end()-1)) = " 47: << min(*v.begin(), *(v.end()-1)); 48: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 49: }