Use array to initialize a set : set « Set Multiset « C++






Use array to initialize a set

  
 

#include <iostream>
using std::cout;
using std::endl;

#include <set>

#include <algorithm>
#include <iterator> // ostream_iterator

int main()
{
   double a[ 5 ] = { 2.1, 4.2, 9.5, 2.1, 3.7 };
   std::set< double, std::less< double > > doubleSet( a, a + 5 );;
   std::ostream_iterator< double > output( cout, " " );

   cout << "doubleSet contains: ";
   std::copy( doubleSet.begin(), doubleSet.end(), output );

   cout << endl;
   return 0;
}

/* 
doubleSet contains: 2.1 3.7 4.2 9.5

 */        
    
  








Related examples in the same category

1.Declare a string set
2.Read keyboard input to a set directly
3.Add elements in a list to a set
4.Create a set that contains list1 - list2
5.Create sets with string elements
6.Assigning sets to each other