Use const_interator to loop through the set : const_interator « STL Algorithms Iterator « C++ Tutorial






#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








30.2.const_interator
30.2.1.const_iterator
30.2.2.Display vector elements using const_iterator
30.2.3.Use const_interator to loop through the set