牛骨文教育服务平台(让学习变的简单)
博文笔记

【C++】判断两个vector是否相等~直接用“==”

创建时间:2016-09-09 投稿人: 浏览次数:5424
  • 如果vector里面的元素类型是简单类型(内置类型),可以直接使用“==”或者“!=”进行比较
因为在STL里面,==和!=是可以直接使用的:
template< class T, class Alloc >
bool operator==( const vector<T,Alloc>& lhs,
                 const vector<T,Alloc>& rhs );

template< class T, class Alloc >
bool operator!=( const vector<T,Alloc>& lhs,
                 const vector<T,Alloc>& rhs );
  • 甚至可以使用“<=” “<” “>=” “>”比较两个vector大小:按照字典序排列
template< class T, class Alloc >
bool operator<( const vector<T,Alloc>& lhs,
                const vector<T,Alloc>& rhs );

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

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

template< class T, class Alloc >
bool operator>=( const vector<T,Alloc>& lhs,
                 const vector<T,Alloc>& rhs );
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。