C++ examples for STL:set
Initialize set with value from array
#include <iostream> #include <set> #include <algorithm> #include <iterator> // ostream_iterator using namespace std; // define short name for set type used in this program typedef set< double, less< double > > DoubleSet; int main() /*from w w w . j av a2 s .co m*/ { const int SIZE = 5; double a[ SIZE ] = { 2.1, 4.2, 9.5, 2.1, 3.7 }; DoubleSet doubleSet( a, a + SIZE ); ostream_iterator< double > output( cout, " " ); cout << "doubleSet contains: "; copy( doubleSet.begin(), doubleSet.end(), output ); }