在C ++中获取集合的交集,交集或差异

编程入门 行业动态 更新时间:2024-10-26 11:27:30
本文介绍了在C ++中获取集合的交集,交集或差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有几个关于如何使用C ++集(std :: set)的问题

I have a couple questions about how to use C++ sets (std::set)

  • 有没有办法得到两个C ++集合的联合,交集或区别? (写自己的功能很容易,但我想知道是否有内置的功能)

  • Is there a way to get the union, intersection, or difference of two C++ sets? (It's pretty easy to write my own functionto do that but I wanted to know if there was a built in function for it)

    可以将C ++集合用作

    Can C++ sets be used as keys in a map?

    推荐答案

    使用 set_difference() , set_union() , set_intersection() 和 set_symmetric_difference() 功能。

    Use the set_difference(), set_union(), set_intersection() and set_symmetric_difference() functions.

    设置和映射支持可以比较的任何键类型。默认情况下,该类型定义了 operator<(),但您可以提供自己的比较器。 C ++集没有定义 operator<(),因此不能用作键,除非您提供自己的比较器。

    Sets and maps support any key type that can compare. By default this means the type has operator<() defined, but you can provide your own comparator. C++ sets don't have operator<() defined and therefore can't be used as keys unless you provide your own comparator.

  • 更多推荐

    在C ++中获取集合的交集,交集或差异

    本文发布于:2023-11-29 18:33:04,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1647252.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:差异

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!