Mega Code Archive

 
Categories / C++ / Vector
 

Checking If Two Containers Are Equal with == operator

#include <algorithm> #include <iostream> #include <list> #include <vector> using namespace std; int main( ) {    short v[] = { 1, 2, 3, 4, 5, 6 };    vector<short> v1( v,v + sizeof( v ) / sizeof( v[0] ) );    vector<short> v2( v1 );    if( v1 == v2 )       cout << "The vectors are equal" << endl;    else       cout << "The vectors are not equal"  << endl;    reverse( v2.begin(), v2.end() );    if( v1 == v2 )       cout << "The vector and reversed vector are equal" << endl;    else       cout << "The vector and reversed vector are not equal" << endl; }