Compare sets with '==' operator : set compare « Set Multiset « C++






Compare sets with '==' operator

  
#include <set>
#include <iostream>
#include <string>

using namespace std;

template <class T>
void print(T& c){
   for( typename T::iterator i = c.begin(); i != c.end(); i++ ){
      std::cout << *i << endl;
   }
}

int main()
{
  set<string> first;

  first.insert("A");
  first.insert("B");
  first.insert("C");

  cout << first.size() << endl;
  set<string> second (first);   // Copy constructor

  second.insert("I");
  second.insert("S");
  second.insert("C");

  cout << second.size() << endl;

  if (first == second)
    cout << "Sets have same elements\n";
  else
    cout << "Not same elements\n";
}
  
    
  








Related examples in the same category

1.set comparison