+1 vote
in C Plus Plus by

1 Answer

0 votes
by
edited by

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.

Related questions

+1 vote
+1 vote
asked Jul 16, 2019 in C Plus Plus by Indian
+1 vote
+1 vote
+1 vote
asked Jul 16, 2019 in C Plus Plus by Indian
...