How to iterate std::set?

The Solution to How to iterate std::set? is

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

If you have C++11 features, you can use a range-based for loop:

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

~ Answered on 2012-10-12 16:23:15

Most Viewed Questions: