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 1209
予麋鹿
予麋鹿 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

    As long as your vector contains elements that in themselves can be compared (have operator==), this works, yes. Note however that if you have a vector that contains for example pointers to identical objects, but not the SAME instance of an object, then the vector is not considered identical, because the element in the vector is what is compared, not the contents of the element as such, if that makes sense.

提交回复
热议问题