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






Use const_interator to loop through the 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.const_iterator
2.Display vector elements using const_iterator