本文介绍了如何迭代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 the value?
推荐答案
您必须取消引用迭代器才能检索集合的成员。
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
}
如果你有C ++ 11的功能,您可以使用:
If you have C++11 features, you can use a range-based for loop:
for(auto f : SERVER_IPS) {
// use f here
}
这篇关于如何迭代std :: set?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!