template <class InputIterator1, class InputIterator2> bool equal( InputIterator1 xFirst1, InputIterator1 xLast1, InputIterator2 xFirst2 );
#include <algorithm>
template <class InputIterator1, class InputIterator2, class BinaryPredicate> bool equal( InputIterator1 xFirst1, InputIterator1 xLast1, InputIterator2 xFirst2, BinaryPredicate xComp );
#include <iostream> #include <vector> #include <algorithm> int main() { using namespace std; // Create two vector instances vector<char> qV1; qV1.push_back('X'); qV1.push_back('o'); qV1.push_back('a'); qV1.push_back('X'); vector<char> qV2; qV2.push_back('X'); qV2.push_back('o'); qV2.push_back('a'); qV2.push_back('X'); qV2.push_back('.'); qV2.push_back('n'); qV2.push_back('e'); qV2.push_back('t'); // Output the vector comparison regions with the first check bool qAreEqual = equal(qV1.begin(), qV1.end(), qV2.begin()); vector<char>::iterator qIter1; for (qIter1 = qV1.begin(); qIter1 != qV1.end(); ++qIter1) { cout << *qIter1; } cout << (qAreEqual ? " is " : "is not " ) << "equal to "; vector<char>::iterator qIter2; for (qIter1 = qV1.begin(), qIter2 = qV2.begin(); qIter1 != qV1.end(); ++qIter1, ++qIter2) { cout << *qIter2; } cout << endl; // Output the vector comparison regions with the second check qAreEqual = equal(qV1.begin(), qV1.end(), qV2.begin() + 1); for (qIter1 = qV1.begin(); qIter1 != qV1.end(); ++qIter1) { cout << *qIter1; } cout << (qAreEqual ? " is " : " is not " ) << "equal to "; for (qIter1 = qV1.begin(), qIter2 = qV2.begin() + 1; qIter1 != qV1.end(); ++qIter1, ++qIter2) { cout << *qIter2; } // Keep the window open cin.get(); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.