How to get the first element of a std::set

c++, iterator, set, stl

Solution

your code work well in VS2010, mybe you should update your vcc.

Problem

I you all, I found a strange bug in my software. Inside a while loop where I remove elements from a std::set, I want always to take the first element until the container is empty: ``` std::set< int*> nodes; // Fill nodes for (int i=0; i<10;i++) nodes.insert(new int); // while (!nodes.empty()) { int* pivot = (*nodes.begin()); // do some operation with pivot erasing some elements from nodes } ``` I found that implementing the first element this way works with gcc but not with MSVC, it crashes where I try to dereference the `(*nodes.begin())` iterator. Do the two implementation of std::set behave differently? I would like to have a data structure with no differences of implementation, is it possible? Probably I must change data structure for this kind of operations

Original source