Initialize set with value from array - C++ STL

C++ examples for STL:set

Description

Initialize set with value from array

Demo Code

#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 ); 
}

Result


Related Tutorials