A map is a collection of a keyvalue pairs , such as an address and phone number keyed to an individual's name. In contrast, a set is simply a collection of keys . For example, a business might define a set named bad_checks, to hold the names of individuals who have issued bad checks to the company. A set is most useful when we simply want to know whether a value is present . Before accepting a check, for example, that business would query bad_checks to see whether the customer’s name was present.
[Note] With two exceptions , set supports the same operations as map. The exceptions are that set does not provide a subscript operator and does not define mapped_type . In a set, the value_type is not a pair: instead it and key_type are the same type. They are each the type of the elements stored in the set. These differences reflect the fact that set holds only key; there is no value associated with the key . As with map, the keys of a set must be unique and may not be changed .
To use a set, we must include the set header . The operations on sets are essentially identical to those on maps.
[An example: to use set]
output:
[Another example]
[set used]
[map used]