/**
@file multiset.cc
@author Mitch Richling <http://www.mitchr.me/>
@Copyright Copyright 2000 by Mitch Richling. All rights reserved.
@brief Example of how to use SETs in the STL specified by C++ 98 .@EOL
@Keywords Standard C++ I/O iostream STL multiset template
@Std C++98
This program is an example of how use the set template in
the STL of C++ 98.
*/
#include <set> /* STL set C++ */
#include <iostream> /* C++ iostream C++ */
int main() {
std::multiset<int> mySet;
mySet.insert(5);
mySet.insert(2);
mySet.insert(1);
mySet.insert(2); // '2' is already in the multiset, so this will insert
// ANOTHER copy -- putting two of them in the multiset.
// This is different from a 'set'.
mySet.insert(4);
// We can traverse the whole thing like this:
std::cout << "All the elements of the set: ";
for(std::set<int>::iterator mySetIter = mySet.begin(); mySetIter != mySet.end(); ++mySetIter)
std::cout << *mySetIter << " ";
std::cout << std::endl;
// One way to check if something is an element of a set is with count().
// Unlike with set, count can be any non-negative value in a multiset.
for(int i=1; i<6; i++)
std::cout << "Looking for " << i << "... Found " << mySet.count(i) << std::endl;
}
Generated by GNU enscript 1.6.4.