previous | start | next

## Other Standard Containers

- The C++ `set` ignore duplicates; if you insert an element into the set that is already present, the insertion has no effect.
- The `count` function returns the number of times that an element is contained in a set (should always be 1).

  >     set<string> s;

  >     s.insert("Tom");
  >     s.insert("Tom");
  >     cout << s.count("Tom") << "\n"; /* displays 1 */

- If you want to be able to keep track of multiple occurrences of identical values, use a `multiset` instead.
- The `count` function works for multiset, with expected results.

  >     multiset<string> m;

  >     m.insert("Tom");
  >     m.insert("Tom");
  >     cout << m.count("Tom") << "\n"; /* displays 2 */

previous | start | next