I am having an unexplained vector out of range error!
for (unsigned int i = 0; i < studentsVector.size(); i++) {
bool anyFailedFacultyCourse = false;
bool anyFailedElectiveCourse = false;
// Check if all faculty courses are done
std::cout << currentSemester << std::endl;
if (currentSemester > 1) {
std::cout << "hi" << std::endl;
for (int j = 0; j < currentSemester - 1; j++) {
if (studentsVector.at(i)->getPlan().at(j).size() > 0) {
anyFailedFacultyCourse = true;
}
}
std::cout << "bye" << std::endl;
After debugging, I noticed that the program does get into the first for loop, assigns proper values for AnyFailedFacultyCourse and anyFailedElectiveCourse, prints the int currentSemester. And there it stops!
I put a debug breakpoint at:
if (currentSemester > 1)
and it just gives me an out_of_range error before it even checks! Meaning it does not even get into if (currentSemester > 1)
But there is nothing in between! I mean, how could it throw anything like that when, where it throws the error, I did NOTHING to any vector!
I know this is kind of mysterious, ask for any further information you need.
Further info:
How students vector is declared:
std::vector<Student*> studentsVector;
currentSemester:
int currentSemester = 1;
I bet the breakpoint you set isn’t triggered because the condition isn’t
true: that is withcurrentSemesterbeing1the condition is clearlyfalseand the code skips to whatever is happening after the conditional block. You haven’t shown what is happening, there, however.