如何迭代std :: set [英] How to iterate std::set

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

问题描述

我有一个代码:

std::set<unsigned long>::iterator it;
for (it = SERVER_IPS.begin(); it != SERVER_IPS.end(); ++it)
{
    u_long f = it; // error here
}

没有 - >第一值。
我如何获得价值?

There is no ->first value. How i can obtain value?

谢谢!

推荐答案

p>您必须取消引用迭代器才能检索集合的成员。

You must dereference the iterator in order to retrieve the member of your set.

std::set<unsigned long>::iterator it;
for (it = SERVER_IPS.begin(); it != SERVER_IPS.end(); ++it)
{
    u_long f = *it; // Note the "*" here
}

,您可以使用基于范围的for循环

for(auto f : SERVER_IPS) {
  // use f here
}    

这篇关于如何迭代std :: set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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