Assigning sets to each other : set « Set Multiset « C++






Assigning sets to each other

  
#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("r");
  first.insert("T");
  first.insert("s");

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

  set<string> second (first);   // Copy constructor

  second.insert("r");
  second.insert("K");
  second.insert("S");
  second.insert("b");

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

  set<string> third = first;

  print(first);
  print(second);
  print(third);

  set<string> set2(first);
  set2.insert("l");
  
  print(set2);
}
  
    
  








Related examples in the same category

1.Declare a string set
2.Use array to initialize a set
3.Read keyboard input to a set directly
4.Add elements in a list to a set
5.Create a set that contains list1 - list2
6.Create sets with string elements