React.js
Angular
Ethical Hacking
Agile
AWS
BlockChain
Cassandra
Cloud
Salesforce
Scaled Agile
TOGAF
DevOps
GIT
Jenkins
Jira
Kibana
Linux
NGINX
Ansible
Artificial Intelligence
Click here to read more about DevOps

1 Answer

0 votes
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

2

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

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