fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <cstdlib>
  4. //using namespace std;
  5. int CompareString( const void * e1, const void * e2) {
  6. std::string * s1 = (std::string * ) e1;
  7. std::string * s2 = (std::string * ) e2;
  8. if( *s1 < *s2 ) return -1;
  9. else if( *s1 == *s2 ) return 0;
  10. else if( *s1 > *s2 ) return 1;
  11. }
  12.  
  13. int main() {
  14. // string Array[4] = {"hehe","789","456","123"};
  15. std::string *Array[4] = {
  16. new std::string("hehe"),
  17. new std::string("789"),
  18. new std::string("456"),
  19. new std::string("123")
  20. };
  21.  
  22. qsort(Array,4,sizeof(std::string *),CompareString);
  23. for( int i = 0;i < 4;++i )
  24. std::cout << *Array[i] << std::endl;
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
hehe
789
456
123