Set operatrions: insert, size, begin, end : Set « Data Structure « C++






Set operatrions: insert, size, begin, end

Set operatrions: insert, size, begin, end

#include <iostream>

#include <string>
#include <set>
using namespace std;

int main()
{
    set<string> setObject;                                                   
    setObject.insert( "a" );                                           
    setObject.insert( "b" );                                              
    setObject.insert( "c" );                                               
    setObject.insert( "d" );                                          
    setObject.insert( "c" );                    // attempting a duplicate   

    cout << setObject.size() << endl;;                                   

    typedef set<string>::const_iterator CI;
    for (CI iter = setObject.begin();                                        
          iter != setObject.end();
          iter++)
       cout << *iter << " "; 

     setObject.erase( "b" );                                               
     cout << setObject.size() << endl;                                   

     for ( CI iter = setObject.begin();                                       
          iter != setObject.end();
          iter++ )
     cout << *iter << " "; 
     return 0;
}


           
       








Related examples in the same category

1.set: insert, end, beginset: insert, end, begin
2.Using a multiset to record responses to a polling question.Using a multiset to record responses to a polling question.