Add elements in a list to a set : set « Set Multiset « C++






Add elements in a list to a set

  
 


#include <iostream>
#include <cassert>
#include <list>
#include <string>
#include <set>
using namespace std;

int main()
{
  string s("There is no distinctly native American criminal class");


  list<char> list1(s.begin(), s.end());

  // Put the characters in list1 into set1:
  set<char> set1;
  list<char>::iterator i;

  for (i = list1.begin(); i != list1.end(); ++i)
    set1.insert(*i);

  set<char>::iterator j;

  for (j = set1.begin(); j != set1.end(); ++j)
    cout << *j;


  return 0;
}

/* 
 ATacdehilmnorstvy
 */        
    
  








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.Create a set that contains list1 - list2
5.Create sets with string elements
6.Assigning sets to each other