I am wondering how I can sort a set that contains strings. For example, I have a set:
std::set<std::string> setA = {"B","A","C"}
Then I wanna use this to do the sorting:
std::sort(setA.begin(),setA.end());
But the C++ compiler cannot let it pass. The error message reports:
40: error: invalid operands to binary expression ('std::__1::__tree_const_iterator, std::__1::__tree_node, void *> *, long>' and 'std::__1::__tree_const_iterator, std::__1::__tree_node, void *> *, long>') difference_type __len = __last - __first;
Then I recheck sort function in C++, it seems that it can only deal with int, double, long ... but there is no way to use this function sort() to sort strings.
So how can I sort strings?
Aucun commentaire:
Enregistrer un commentaire