Storing Objects in Sorted Order - C++ STL

C++ examples for STL:set

Description

Storing Objects in Sorted Order

Demo Code

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

using namespace std;

int main() {//from   www  .  ja v  a 2 s .c om

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

   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;
}

Result


Related Tutorials