<<< std::stack | Index | std::pair structure >>> |
A
The elements in std::set are always sorted.
#include <cassert> #include <iostream> #include <set> using namespace std; int main (int argc, char* argv[]) { set< int > iset; // set of unique integer numbers iset.insert( 11 ); // populate set with some values iset.insert( -11 ); iset.insert( 55 ); iset.insert( 22 ); iset.insert( 22 ); if ( iset.find( 55 ) != iset.end() ) { // is value already stored? iset.insert( 55 ); } assert( iset.size() == 4 ); // sanity check :-) set< int >::iterator it; for ( it = iset.begin(); it != iset.end(); it++ ) { cout << " " << *it; } return 0; } // Output: -11 11 22 55
<<< std::stack | Index | std::pair structure >>> |