Hi ;
Please help on the code below. I want sort the names entered by the user in Ascending and descending order but the ascending order is not working and I have comment that one out.
sort(names.end(),names.begin());
Never ever do that. End iterator should be after begin iterator, that means if you will increment begin iterator it in the end will become equal to end and all its value will be within single container. Otherwise you get undefined behavior.
To sort in another order you can simply pass another comparsion function:
std::sort takes three parameters. First is iterator to the beginning of range. Second is the one-past-the-end iterator. Third optional one is the function which will be used for comparsion. By default operator < is used.
You can define function yourself of use templated one provided by standard library. Example: