template <class ForwardIterator, class X> ForwardIterator upper_bound( ForwardIterator xFirst, ForwardIterator xLast, const Type& kxrTarget );
#include <algorithm>
template <class ForwardIterator, class X, class BinaryPred> ForwardIterator upper_bound( ForwardIterator xFirst, ForwardIterator xLast, const Type& kxrTarget, BinaryPred xComp );
#include <iostream> #include <vector> #include <algorithm> int main() { using namespace std; // Create a vector instance vector<int> qV; // Add the first eight even entries for (int i = 0; i < 16; i += 2) { qV.push_back(i); } vector<int>::iterator qIter; cout << "Ordered Vector: "; for (qIter = qV.begin(); qIter != qV.end(); ++qIter) { cout << *qIter << " "; } cout << endl; // Find the least element that is greater than 9 qIter = upper_bound(qV.begin(), qV.end(), 9); cout << *qIter << " is the upper bound of 9" << endl; // Keep the window open cin.get(); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.