Or login with:
#include <algorithm> template < class InputIterator1, class InputIterator2 > bool equal( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 ); template < class InputIterator1, class InputIterator2, class BinaryPredicate > bool equal( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate comp );Parameters:
| Parameter | Description |
|---|---|
| first1 | An input iterator addressing the position of the first element in the first range to be tested |
| last1 | An input iterator addressing the position one past the final element in the first range to be tested |
| first2 | An input iterator addressing the position of the first element in the second range to be tested |
| comp | User-defined predicate function object that defines the condition to be satisfied if two elements are to be taken as equivalent. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied |
i in [first1, last1),
*i == *(first2 + (i - first1)).
The second version of equal returns true if and only if for every iterator i in [first1, last1), comp(*i, *(first2 + (i - first1)) is true.last1 - first1 comparisons..#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a1[] = {4, 3, 7, 5, 6}; vector<int> v1(a1, a1+5); cout <<"\nHere are the contents of v1:\n"; for (vector<int>::size_type i=0; i<v1.size(); i++) cout <<v1.at(i)<<" "; int a2[] = {1, 2, 4, 3, 7, 5, 6, 8, 9, 10}; vector<int> v2(a2, a2+10); cout <<"\nHere are the contents of v2:\n"; for (vector<int>::size_type i=0; i<v2.size(); i++) cout <<v2.at(i)<<" "; cout <<"\nFirst we compare the sequence in v1 and the sequence " "starting\nat the beginning of v2, and ask whether they match."; if (equal(v1.begin(), v1.end(), v2.begin())) cout <<"\nYes, they match."; else cout <<"\nNo, they don't match."; cout <<"\nThen we compare the sequence in v1 with the sequence " "starting\nat the third value of v2, and ask whether they match."; if (equal(v1.begin(), v1.end(), v2.begin()+2)) cout <<"\nYes, they match."; else cout <<"\nNo, they don't match."; return 0; }
You must login to leave a messge