Declare a string set : set « Set Multiset « C++






Declare a string set

  
 

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

using namespace std;

int main( ) {

   set<string> setStr;
   string s = "B";

   setStr.insert(s);
   s = "S";
   setStr.insert(s);
   s = "R";
   setStr.insert(s);
   s = "H";
   setStr.insert(s);

   for (set<string>::const_iterator p = setStr.begin( );p != setStr.end( ); ++p)
      cout << *p << endl;
}

/* 
B
H
R
S

 */        
    
  








Related examples in the same category

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