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