将向量的元素添加到无序集合 [英] adding elements of a vector to an unordered set

查看:19
本文介绍了将向量的元素添加到无序集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以将 vector 的所有元素添加到 unordered_set 中?它们属于同一类型.现在,我正在使用 for 循环,想知道是否有更好的方法来做到这一点

Is there an easy way to add all the elements of a vector to an unordered_set? They are of the same type. Right now, I am using a for loop and was wondering if there is a better way to do it

推荐答案

如果您正在构建 unordered_set 那么:

If you're constructing the unordered_set then:

std::vector<int> v;
std::unordered_set<int> s(v.begin(), v.end());

这篇关于将向量的元素添加到无序集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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