How to compare vectors in C++

2 Answers

0 votes
#include <iostream>
#include <vector>

int main ()
{
    std::vector<int> v1 = { 5, 2, 7, 1, 9 };
    std::vector<int> v2 = { 5, 2, 7, 9, 1 };

    v1 == v2 ?
        std::cout << "v1 == v2" :
        std::cout << "v1 != v2";

    return 0;
}
    
    
    
    
/*
run:
  
v1 != v2
     
*/

 



answered May 11, 2021 by avibootz
0 votes
#include <iostream>
#include <vector>

int main ()
{
    std::vector<int> v1 = { 5, 2, 7, 1, 9 };
    std::vector<int> v2 = { 5, 2, 7, 1, 9 };

    equal(v1.begin(), v1.end(), v2.begin(), v2.end()) ?
        std::cout << "v1 == v2" :
        std::cout << "v1 != v2";

    return 0;
}
    
    
    
    
/*
run:
  
v1 == v2
     
*/

 



answered May 11, 2021 by avibootz
...