template <class ForwardIterator> ForwardIterator max_element( ForwardIterator xFirst, ForwardIterator xLast );
#include <algorithm>
template <class ForwardIterator, class BinaryPred> ForwardIterator max_element( ForwardIterator xFirst, ForwardIterator xLast, BinaryPred xComp );
#include <iostream> #include <vector> #include <algorithm> int main() { using namespace std; // Create a vector instance vector<char> qV; qV.push_back('X'); qV.push_back('o'); qV.push_back('a'); qV.push_back('X'); qV.push_back('.'); qV.push_back('n'); qV.push_back('e'); qV.push_back('t'); vector<char>::iterator qIter; // Output the vector cout << "The Vector: "; for (qIter = qV.begin(); qIter != qV.end(); ++qIter) { cout << *qIter; } cout << endl; // Find the maximum qIter = max_element(qV.begin(), qV.end()); // Output the largest cout << "The largest is: " << *qIter << endl; // Keep the window open cin.get(); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.