3

How to read from std vector front and remove read variable?

Is it:

v.front();
v.erase(v.begin());
myWallJSON
  • 9,110
  • 22
  • 78
  • 149
  • 4
    You didn't exactly do anything with the value you got from it. If this is all you're doing, you might consider something like a stack, though, depending on what else you need to do with it. – chris Dec 07 '12 at 06:10
  • 3
    Removing from the front is expensive. – Pubby Dec 07 '12 at 06:17

1 Answers1

8

That looks about right, but consider switching to a std::deque which has a pop_front function (which won't have to move all the elements in the container)

Andreas Brinck
  • 51,293
  • 14
  • 84
  • 114