Add elements in a list to a set : set « set multiset « C++ Tutorial






#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"








19.1.set
19.1.1.Declare a string set
19.1.2.Use array to initialize a set
19.1.3.Read keyboard input to a set directly
19.1.4.Assigning sets to each other
19.1.5.Add elements in a list to a set