c++ - Qsort doesn't sort properly array of strings -


i'm trying sort array declared string *names1 = new string[1]; (the size of array growing adding more items).

i'm putting there strings. items in array before sorting are: novot svobodovaa novakj6 3 vondraj1234

after calling qsort(names1, size, sizeof (string), compare);, compare implemented this

int compare(const void * a, const void * b) { return ( *(char*) - *(char*) b); } 

the items in array scrambled way vondraj1234 novakj6 novot svobodovaa

does know, can bug doesn't allow me sort array in alphabetical order?

you can only use qsort types can copied memcpy. std::string (and other type non-trivial assignment operator) not qualify. instead, use std::sort. knows how copy objects correctly.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -