Search code examples
c++stdvector

How to compare two vectors for equality element by element?


Is there any way to compare two vectors?

if (vector1 == vector2)
    DoSomething();

Note: Currently, these vectors are not sorted and contain integer values.


Solution

  • Check out the std::mismatch method of C++.

    Comparing vectors has been discussed on DaniWeb forum and also answered:

    C++: Comparing two vectors

    Check out the below SO post. It will be helpful to you. They have achieved the same with two different methods.

    How do I get the number of different or common elements between two vectors of strings?