I'm working on a student information system so that I have this struct to store student information:
struct student_info
{
string name;
int id;
string course;
int percent;
};
I have also made this sorting function:
bool sorting(const container &a, const container &b) {
return a.percent < b.percent;
}
Here, I read from a file and store in the struct, push it into the vector of struct and then sort it:
student_info raw_data;
vector <student_info> container;
ifstream infile("data.txt");
while(!infile.eof())
{
infile >> raw_data.name >> raw_data.id >> raw_data.course >> raw_data.percent;
container.push_back(raw_data);
}
sort(container.begin(), container.end(), sorting);
Then, I saw this somewhere but it didn't clearly explain why I don't need brackets even though sorting is a function like why is it just sorting
and not sorting()
when sort is called?