c++ - Sorting strings in Vector algorithim not working -
i have vector of struct items has string inside. trying sort vector of items having string within items in alphabetical order... far have:
vector<item> sorter; std::sort(sorter.begin(), sorter.end(), sorthelp); //predcate function bool sorthelp(item const& one, item const& two) { homecoming one.type < two.type; }
*type string using sort
how alter predicate function sort strings alphabetically?
the next function case-insensitive compare on 2 std::string
s without external libraries (it c++11 though).
bool caseinsensitivecompare(string s1, string s2) { locale loc; std::transform(s1.begin(),s1.end(),s1.begin(), [loc](char c){return std::toupper<char>(c,loc);}); std::transform(s2.begin(),s2.end(),s2.begin(), [loc](char c){return std::toupper<char>(c,loc);}); homecoming (s1 < s2); }
c++ function sorting
No comments:
Post a Comment