c++ - How do I compare two strings?(less than) -


i have program in c++ given large file of uc students already sorted id. need sort school name attending , students attending same school sorted id in ascending order.

ie. joe paarmann,3,ucb 

i need implement given function

bool comparebyschoolname(student s1, s2) compares 2 students school name should return true if , if s1 school comes before (is less than) s2 school

and use sort function sort(students,students+ len, comparebyschoolname);

my problem how compare school names since strings? i'm confused how start this. thank appreciated.

bool comparebyschoolname(student s1, student s2) {  } 

ok buddy, reference: http://www.cplusplus.com/reference/algorithm/sort/

you can see comp parameter following:

binary function accepts 2 elements in range arguments, , returns value convertible bool. value returned indicates whether element passed first argument considered go before second in specific strict weak ordering defines. function shall not modify of arguments. can either function pointer or function object.

so have

bool comparebyschoolname(student s1, student s2) {  return s1.schoolname< s2.schoolname; } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -