Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: Advanced
Jul 11, 2005



Application Security Testing: An Integral Part of DevOps

Incrementing Iterators

You can use iterators for a STL set object to loop through the set elements 1 by 1. But did you know you can also increment the iterator by more than 1? Here's an example:

const int GetNextProduct(const unsigned int uiIndex)
    ProductSet::const_iterator        itElement, it = m_ProductSet.begin();
    unsigned int                    ui = 0;
    while ((++ui - 1) <= uiIndex)
        itElement = m_ProductSet.find(*it);
        if (itElement == m_ProductSet.end())
            TraceW("No more products found, found [%u] products in total", ui - 1);
            return -1;
        ++it; // Can I also do it += 2???
    return *itElement;
Wael Salman
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date