Use copy to output value in set - C++ STL

C++ examples for STL:set

Description

Use copy to output value in set

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  .ja v  a  2s .  c o  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