Insert array to multiset - C++ STL

C++ examples for STL:multiset

Description

Insert array to multiset

Demo Code

#include <iostream> 
 #include <set> // multiset class-template definition 
 #include <algorithm> // copy algorithm 
 #include <iterator> // ostream_iterator 
using namespace std; 

// define short name for multiset type used in this program 
typedef multiset< int, less< int > > Ims; 

int main() /*w  w  w  .j  ava2 s. c  om*/
{ 
   const int SIZE = 10; 
   int a[ SIZE ] = { 7, 22, 9, 1, 18, 30, 100, 22, 85, 13 }; 
   Ims intMultiset; // Ims is typedef for "integer multiset" 
   ostream_iterator< int > output( cout, " " ); 

   intMultiset.insert( 15 ); // insert 15 in intMultiset 
   intMultiset.insert( 15 ); // insert 15 in intMultiset 

   // iterator that cannot be used to change element values 
   Ims::const_iterator result; 

   // insert elements of array a into intMultiset 
   intMultiset.insert( a, a + SIZE ); 
   cout << "\nAfter insert, intMultiset contains:\n"; 

   copy( intMultiset.begin(), intMultiset.end(), output ); 


}

Result


Related Tutorials