Refer To Specific Element in a List

Hello,

I have the following code which at one point used a Vector and not a List

position newPos;
position currentpos = wset[current]; //wset.back();
current++;

(position is a class)

The problem is wset is now a List as I needed to be able to pop the front value off it. I need to be able to refer to the next element in the List, this was done using "current" which would increase each time round the loop and would break out once the end of the Vector was reached.

Is there a way to do something like that using a list?

Thanks
All standard containers (vector,list,deque, also MAYBE set and map) refer to elements by subscript. So yes that's how you would do it. (assuming you use the standard list of course!)
std::list doesn't have subscripting operator, it works with iterators.
If you want a container which uses subscripting and which can pop the front value use a std::deque
Topic archived. No new replies allowed.