-2

I have two vectors

vector<TestResults> testResults;
vector<Students> students;

both have studentId. After I've deleted a student from the student vector I want to delete his testresults from testResults.

I want to delete every record on testResults with studentId == 0.

therainmaker
  • 4,253
  • 1
  • 22
  • 41
Emsal
  • 107
  • 9
  • 1
    And what have you tried so far? – therainmaker Sep 02 '15 at 16:21
  • I haven't found anything related to my question. Maybe it sounds like a pretty simple question. to delete a student I did students.erase(students.begin() + choice); but I can't do that here – Emsal Sep 02 '15 at 16:23
  • http://stackoverflow.com/questions/3385229/c-erase-vector-element-by-value-rather-than-by-position didn't help me at all. Everything is with an int, not an object. – Emsal Sep 02 '15 at 16:37
  • you may want to give us more information about the structures of testResults and Students – therainmaker Sep 02 '15 at 16:43
  • The top answer on the linked question addresses exactly what you are trying to do. – Barry Sep 02 '15 at 19:33
  • Maybe, I don't understand any of it. The answer below was directed more to my case I feel. – Emsal Sep 02 '15 at 21:28

1 Answers1

0
vector<TestResults>::iterator it = testResults.begin();
for (; it != testResults.end();) {
    if (it->studendId == 0) {
        it = testResults.erase(it);
    }
    else {
        ++it;
    }
}
anand
  • 11,071
  • 28
  • 101
  • 159