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);
Aucun commentaire:
Enregistrer un commentaire