1. 程式人生 > >【C++】判斷兩個vector是否相等~直接用“==”

【C++】判斷兩個vector是否相等~直接用“==”

  • 如果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 );