//Update, I ended up figuring it out. If you're curious, I described it in the comments, thanks again everyone!
I am making a program to do several things for a Registrar's office, such as register students, delete students, etc. In the code provided, I am essentially taking in a vector that holds the names of the courses, looking through it to match it with a student id, and then appending certain variables together, putting them into a vector, then printing it out!
The problem: This code compiles 100% fine with no problems, and prints the student ID, and the courses they're registered to.
However, when I try and run this multiple times again, it will start doubling what it prints. So it seems to me that it has something to do with the vector still holding its values after the function is done. So then I decided to try and use the .erase and .clear function vector members, even making a loop to delete the variables, and it will NOT delete what is inside the container.
Does anyone have any ideas?
Here is an example of what happens the first time, then the second in the console:
1st time:
"Report Card for student: 10090"
"__________________________ "
"CS101 70 "
"CS102 65 "
"CS212 85 "
"-------------------------- "
2nd time:
"Report Card for student: 10090"
"__________________________ "
"CS101 70 "
"CS102 65 "
"CS212 85 "
"CS101 70 "
"CS102 65 "
"CS212 85 "
"-------------------------- "
Any help is VERY much appreciated! Thank you.
void printReport(vector<string>& vect){
string studentID;
string line;
string mark;
string temp;
string temp1;
string tempholder;
vector<string> reportCardVect;
ifstream classFile;
cout << "Please enter the ID of the student who's grade report you would like to print: " << endl;
cin >> studentID;
for (int i = 0; i < vect.size(); i++){
tempholder = vect[i];
classFile.open(tempholder.append(".txt"));
while (!classFile.eof()){
getline(classFile, line);
temp = line;
line.erase(line.begin() + 5, line.end());
if (studentID == line){
temp.erase(temp.begin(), temp.begin() + 6);
temp1 = vect[i];
temp1.append(" ");
temp1.append(temp);
reportCardVect.push_back(temp1);
break;
}
}
classFile.close();
}
system("cls");
cout << "Report Card for student: " << studentID << endl;
cout << "_________________________" << endl;
for (int i = 0; i < reportCardVect.size(); i++)
cout << reportCardVect[i] << endl;
cout << "-------------------------" << endl;
cout << endl;
for (int i = 0; i < reportCardVect.size(); i++){
reportCardVect[i].erase();
}
system("pause");
}