Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ help.

  1. Mar 25, 2005 #1
    Hi, I've been having trouble erasing elements from a <vector> (that is from the STL of C++)

    See I declared 2 vectors V and S, V contains lets say all the elements, while S is a solution set which contains some elements that are classified... well yeah....

    I need to create V-S which is a vector that has all the elements in V that are not in S.. I was planning on doing this by making a copy of V into V_S and then erasing every element I add to S from V_S.

    sort of like this:


    I get an error... Why?
  2. jcsd
  3. Mar 26, 2005 #2
    What kind of error do you get? Compilation error?
    I would suggest you to iterate with a loop through all the elements of V_S and check with a vector method (I think called exists()) if each element also exists in vector S. If yes just remove them.
  4. Mar 26, 2005 #3
    You have to pass an iterator to erase, not the element you want to remove.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook