C++ examples for STL:multiset
Count element 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() //w w w . j a v a 2 s .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, " " ); cout << "There are currently " << intMultiset.count( 15 ) << " values of 15 in the multiset\n" ; intMultiset.insert( 15 ); // insert 15 in intMultiset intMultiset.insert( 15 ); // insert 15 in intMultiset cout << "After inserts, there are " << intMultiset.count( 15 ) << " values of 15 in the multiset\n\n"; }