break not working or code error

So I have code to push back in to a vector, but before it pushes back it is supposed to check if parts of the vector match and then perform a replace if they do.

Function
1
2
3
4
5
6
7
8
9
10
11
void Database::savestudentgrade(Grades g1){
	for(int i=0; i<grades.size(); i=i+1){
		Grades g2;
		g2=grades[i];
		if (g2==g1){
		replace (grades.begin(), grades.end(), g2,g1);
		break;
		}
	}
	grades.push_back(g1);
	}



CMD PROMPT
1
2
3
4
5
>>save-student-grade
>>gradesoriginal

>>save-student-grade
>>gradesnew


When I check output it contains

gradesnew

gradesnew


Any ideas?

why dont u use the set container instead of vector, it stores only unique elements, u dont have to do all these checks.
http://www.cplusplus.com/reference/stl/set/
Topic archived. No new replies allowed.