If you're sorting std::strings, that will do. If you want to sort some object or char* you will have to either write operator < or a comparison function.
Yes it will work with strings.
Sort algorithm takes only 2 mandatory parameters, the beginning and the ending of the range to be sorted. How much more simplified can it get?
You do not have to use vectors. You may just use arrays as well.
See example code below for using sort with arrays (code not compiled and tested)
Actually I also used to think for built-in datatype the sort will do but if I have a business user defined sorting order for them, I also need to either write operator < or a comparison function.
E.g
User want int 1 , 5 to be in-front and all other int values to sort behind 1 and 5. This is what I mean by customized sorting order.
Since you are using char* instead of std::string, you must supply the third argument to the sort algorithm to properly sort the names. Your compare function should look like this:
1 2 3 4 5 6
bool const_char_less( constchar* lhs, constchar* rhs )
{
// Return true if and only if the LHS is strictly alphabetically less than the RHS.
// There are functions (like strcmp() in <cstring>) to do this, or you
// can write your own...
}
Then you can sort your array of char*
1 2 3 4 5
std::sort(
my_array_of_names, // The beginning of the array
my_array_of_names + N, // The end, where N is the number of names in the array
const_char_less // The function to use to compare two elements
);
All said, however, you will have a much easier time if you do as suggested above to use std::string instead of char arrays.