Is there any way to compare two vectors?
if (vector1 == vector2) DoSomething();
Note: Currently, these vectors are not sorted and contain integer values.
Your code (vector1 == vector2) is correct C++ syntax. There is an == operator for vectors.
vector1 == vector2
==
If you want to compare short vector with a portion of a longer vector, you can use theequal() operator for vectors. (documentation here)
equal()
Here's an example:
using namespace std; if( equal(vector1.begin(), vector1.end(), vector2.begin()) ) DoSomething();
2.1m questions
2.1m answers
60 comments
57.0k users