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 1205
予麋鹿
予麋鹿 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:02

    Yes. A good reference is cppreference.com, where you can look up operator== for vector, for example on this page: non-member operators, and you will find:

    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.

提交回复
热议问题