[Solved] sort vector of struct element


std::vector<student_t> st;
for(unsigned i = 0; i < 10; ++i) st.push_back(student_t());
std::sort(st.begin(), st.end(), &compare);

You could also use this vector constructor instead of lines 1-2:

std::vector<student_t> st (10 /*, student_t() */);

Edit:

If you want to enter 10 students with the keyboard you can write a function that constructs a student:

struct student_t &enter_student()
{
     student_t s;
     std::cout << "Enter name" << std::endl;
     std::cin >> s.name;
     std::cout << "Enter age" << std::endl;
     std::cin >> s.age;
     std::cout << "Enter score" << std::endl;
     std::cin >> s.score;
     return s;
}
std::vector<student_t> st;
for(unsigned i = 0; i < 10; ++i) st.push_back(enter_student());

1

solved sort vector of struct element