std::vector provides an equality comparison operator==, it can be used to compare the contents of two vectors. For each element in the vector it will call operator == on the elements for comparisons.
Let’s see how to do that,
Suppose we have 2 vectors of int i.e.
1
|
std::vector<int> vecOfNums1{ 1, 4, 5, 22, 33, 2, 11, 89, 49 };
std::vector<int> vecOfNums2{ 1, 4, 5, 22, 33, 2, 11, 89, 49 }; |
Let’s compare 2 vector using operator == i.e.
4
5
6
7 |
Comparing vectors using operator ==
if (vecOfNums1 == vecOfNums2)
{
std::cout << "matched" << std::endl;
} |
If contents of vectors are equal than it will return true else false.