sorting vector!

Hi!
i am new in C++ and i faced to a problem in my first project!
it is the story:

i have a class named "Student" which has 2 properties: StudentName and programCode.on the other hand i have a vector which contains the student's objects. what i wanna do is simply sort students by their names form the vector!
i've read several examples about sort() in <algorithm.h> but those were not useful for my case!

i defied a function in class student that return the student's name but don know how to use it as something with the sort() method!

Student.getName() "return name"
Student.getProgramCode() "return program code"
vector<Student> students; "the vector that contains the student's objects"

i will appreciate any help of you!
Overload the < operator for Student class
if the name is a string this should make sort working:
1
2
3
4
bool Student::operator < ( const Student &cmp )
{
     return getName() < cmp.getName();
}


http://www.cplusplus.com/reference/algorithm/sort.html
Last edited on
Topic archived. No new replies allowed.