C++ sort array of strings

后端 未结 6 1889
渐次进展
渐次进展 2021-01-01 15:28

I am trying to sort an array of strings, but it\'s not sorting anything.... what am I doing wrong?

string namesS[MAX_NAMES];

int compare (const void * a, co         


        
6条回答
  •  天涯浪人
    2021-01-01 15:53

    std::qsort is inherited from the standard C library. It will not work.

    You need to use std::sort for sorting strings.

    Specifically, cast std::string to void* and then to char* is undefined and won't work.

提交回复
热议问题