How to iterate over a specific range of std::set/std::multiset?

  associative-array, c++, stl

For an std::set like std::set<std::string> set={ "aaa", "bbb", "ccc", "ddd", "eee", "fff" };
how to iterate over a specific range [a, b] of this set without tracking of extra indexes?

Something like this:

for(auto it = set.begin(); it!=set.begin()+b; ++it)
   std::cout << *it << " ";

Or like this:

for(auto it = set.begin()+a; it!=set.begin()+b; ++it)
   std::cout << *it << " ";

where a<=b and b<=set.size()

Source: Windows Questions C++

LEAVE A COMMENT