through set c++ code example
Example 1: loop through set c++
#include <iostream>
#include <set>
int main ()
{
int myints[] = {75,23,65,42,13};
std::set<int> myset (myints,myints+5);
std::cout << "myset contains:";
for (std::set<int>::iterator it=myset.begin(); it!=myset.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
Example 2: iterate over a set in C++
for (auto& i : mySet)
{
cout << i << " , ";
}
for_each(mySet.begin(), mySet.end(), [](const auto & str)
{
cout<<str<<", ";
});
set<string>::iterator it = mySet.begin();
while (it != mySet.end())
{
cout << *it << ", ";
it++;
}
Example 3: through set c++
for (auto& i : mySet)
{
cout << i << " ";
}
for_each(mySet.begin(), mySet.end(), [](const auto & str)
{
cout<<str<<" ";
});
set<string>::iterator it = mySet.begin();
while (it != mySet.end()) {
cout << *it << " ";
it++;
}
for (set<int>::iterator it=myset.begin(); it!=myset.end(); ++it)
cout <<*it << " ";