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:

    S.push_back(x);
    V_S.erase(x);

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: C++ help.
  1. Some C++ help please (Replies: 6)

  2. C-Programming Help (Replies: 6)

  3. C++ help (Replies: 7)

  4. C++ for loop help (Replies: 6)

  5. C++ program help (Replies: 2)

Loading...