如何检查一个元素是否在std :: set? [英] How to check that an element is in a std::set?

查看:826
本文介绍了如何检查一个元素是否在std :: set?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查元素是否在集合中?



是否有一个更简单的等价于下面的代码:

  myset.find(x)!= myset.end()


<

 <$ c> 

$ c> const bool is_in = container.find(element)!= container.end();


How do you check that an element is in a set?

Is there a simpler equivalent of the following code:

myset.find(x) != myset.end()

解决方案

The typical way to check for existence in many STL containers is:

const bool is_in = container.find(element) != container.end();

这篇关于如何检查一个元素是否在std :: set?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆