C++ examples for STL:multiset
Using copy function to ouput value in multiset
#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() //from www . j a v a 2s. co m { 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 ); }