The set Type

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]



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值