how to iterate over set in c++ code example
Example 1: iterating a set c++
//Given set s
for(auto it: s){
cout << it << endl;
}
Example 2: through set c++
//Method 1
for (auto& i : mySet)
{
cout << i << " ";
}
//Method 2
for_each(mySet.begin(), mySet.end(), [](const auto & str)
{
cout<<str<<" ";
});
//Method 3
set<string>::iterator it = mySet.begin();
while (it != mySet.end()) {
cout << *it << " ";
it++;
}
//Method 4
for (set<int>::iterator it=myset.begin(); it!=myset.end(); ++it)
cout <<*it << " ";