for my project I need to make the iterators from the loop to go to the next item in the container, do some operations, and return again back to the same iterator and just continue, however, for some reason neither advance nor next and then using prev seem to work. So how could I get the next iterator and just return to prev one?
I get the following error message :
no matching function for call to 'next(int&)'
no type named 'difference_type' in 'struct std::iterator_traits<int>'
Thank you!
template<class T>
void insert_differences(T& container)
{
    for(auto it : container){
        // do some operations here
        //advance(it,1);
        it = next(it); 
        // do some operations here 
        //advance(it, -1);
        it = prev(it);
        }
}
 
                        
Range-based for loop iterates over elements. The name
itis confusing here; it's not iterator but element, that's whystd::nextandstd::prevdon't work with it.You have to write the loop using iterators by yourself like