Hello can anyone help me with sorting this struct by name and surname? Ive done like this and it doesn't sort it.
Thanks
Code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct student
{
int st_studenta;
string vpisna;
string ime;
string priimek;
};
student vpis(int st_studenta)
{
student student;
string vpisna,ime,priimek;
cout<<endl<<"Vnesite vpisno številko študenta: ";
cin>>vpisna;
cout<<endl<<"Vnesite ime študenta: ";
cin>>ime;
cout<<"Vnesite priimek študenta: ";
cin>>priimek;
student.st_studenta=st_studenta+1;
student.vpisna=vpisna;
student.ime=ime;
student.priimek=priimek;
return student;
}
void izpis(student student)
{
cout<<endl<<"St. študenta: "<<student.st_studenta;
cout<<endl<<"Vpisna: "<<student.vpisna<<endl;
cout<<endl<<"Ime: "<<student.ime<<endl;
cout<<endl<<"Priimek: "<<student.priimek<<endl;
}
bool sort_by_name( const student & lhs, const student & rhs )
{
return lhs.ime < rhs.ime;
}
bool sort_by_age( const student & lhs, const student & rhs )
{
return lhs.priimek < rhs.priimek;
}
int main()
{
int st_studentov=0;
student seznam_student[50];
int meni;
do
{
cout<<"-------MENU-------------"<<endl;
cout<<"________________________"<<endl;
cout<<"1. Vnos študenta "<<endl;
cout<<"2. Izpis študentov "<<endl;
cout<<"3. Sortiranje študentov "<<endl;
cout<<"4. Najdi študenta "<<endl;
cout<<"0. Izhod "<<endl;
cout<<"========================"<<endl;
cin>>meni;
if(meni==1)
{
seznam_student[st_studentov]=vpis(st_studentov);
st_studentov++;
}
if(meni==2)
{
for(int a=0;a<st_studentov;a++)
{
izpis(seznam_student[a]);
}
}
if(meni==3)
{
std::vector<student> people;
std::sort( people.begin(), people.end(), sort_by_name );
std::sort( people.begin(), people.end(), sort_by_age );
}
}while(meni!=0);
return 0;
}