Can I use ' == ' to compare two vectors. I tried it and seems to be working fine. But I don't know whether it will work in more complex situations

前端 未结 6 1201
予麋鹿
予麋鹿 2021-02-01 12:30

First example:

int main(){
    using namespace std;   
    vector v1{10, 20, 30, 40, 50};
    vector v2{10, 20, 30, 40, 50};

    if(v1==v2         


        
6条回答
  •  死守一世寂寞
    2021-02-01 13:09

    You can check the documentation of operator== for vector: operator==,!=,<,<=,>,>=(std::vector)

    Quoting from the link:

     template< class T, class Alloc >
     bool operator==( vector& lhs,
                 vector& rhs );
    

    Compares the contents of two containers.

    Checks if the contents of lhs and rhs are equal, that is, whether lhs.size() == rhs.size() and each element in lhs has equivalent element in rhs at the same position.

    parameters:

    lhs, rhs containers whose contents to compare

    T must meet the requirements of EqualityComparable in order to use versions

    Return value

    true if the contents of the containers are equivalent, false otherwise

提交回复
热议问题