0

I'm quite stuck on this function for a c++ program.

Instructions Write a function called RemoveGrades that takes the student array and grade vector as parameters, it asks the user for a valid assignment number, loops through each student, and removes the selected assignment from each student's grades vector.

I've searched a lot about deleting specific elements from vectors but can't seem to figure out how to get vector.erase() to work. I think the issue is that I'm working with a vector of arrays of ints.

code

given

// may be declared outside the main function const int NUM_STUDENTS =3; // may only be declared within the main function string Students[NUM_STUDENTS] = {"Eric","Stacy","Mark"}; vector <int> grades[NUM_STUDENTS] { {10,98,88,99,57}, {62,80,94,100,93}, {11,82,28,85,38} }; void RemoveGrades(string Students[],vector<int> grades[],int numstudents){ cout<<"Remove assignment"<<endl; int assignmentNum; assignmentNum=getValidAssignmentNumber(); for (int index=0;index<numstudents;index++) { grades[index].erase(assignmentNum); } } 

If I put in two arguments in grades[index].erase clion tells me I need one argument, and if I put one it tells me I need two. Any help is appreciated. Thanks

Error messages

No matching member function for call to 'erase' candidate function not viable: requires single argument '__position', but 2 arguments were provided

In function 'void RemoveGrades(std::string*, std::vector*, int)': /cygdrive/c/Users/Ryan Foster/CLionProjects/arrays_and_vectors_second_try/main.cpp:191:56: error: no matching function for call to 'std::vector::erase(int&, int&)' grades[index].erase(assignmentNum,assignmentNum);

3
  • 1
    Please include the compiler error verbatim. Also, note that vector::erase does not take in an index. Commented Mar 27, 2020 at 16:50
  • 1
    That's not a vector of arrays of ints; it's an array of vectors of ints. Commented Mar 27, 2020 at 16:52
  • You could make your own erase method. Since you are using vectors though, you can do grades[index].erase( grades[index].begin() + assignmentNum ); Still an iterator, but a bit easier. Commented Mar 27, 2020 at 16:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.