This is my current code:
#include <list>
#include <string>
using std::string;
using std::list;
int main()
{
list <string> list_;
list_.push_back("C");
list_.push_back("a");
list_.push_back("b");
list_.sort();
}
Does the sort() function sort the elements according to their character codes? I want the result here to be a b C after the sorting is done.
The default comparator (
<) using the defaultchar_traits< char >will sort your list asC a b.See list::sort.
In order to achieve the desired order
a b Cyou can either:stringtypes with customchar_traits, orprovide an instance of a custom string comparator to
sort, e.g.