判断两个vector是否相等

来源:百度知道 编辑:UC知道 时间:2024/05/02 07:37:31
如:......
vector<int> ivec1,ivec2;
.......
可以直接ivec1==ivec2;这样写吗?
还是必须用迭代器遍历容器内元素来比较?

可以直接用==比较。

下面是vecotr的==的函数模板说明:

Operations == and != are performed by comparing the elements using algorithm equal.

template <class T, class Allocator>
bool operator== ( const vector<T,Allocator>& x, const vector<T,Allocator>& y );