Re: sorting std::vector<string> ignoring case



Ed wrote:
I need to sort a vector of strings ignoring case while preserving it. That is, if I have a vector containing "Xyz" and "abc" I
want to report "abc" "Xyz". I can think of several inelegant ways, such as creating a second vector with all upper (or lower)
and sort it while saving the sort order in an integer array, using the latter to index the while reporting the original vector...
that is, an indirect sort. But I was wondering if there was some why of accomplishing this more directly with the
STL algorithms.


Here is the sample that works:

#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <iostream>

struct LessNoCase {
bool operator()(const std::string &x, const std::string &y) const {
return (stricmp (x.c_str(), y.c_str()) < 0);
}
};


int main() {

std::vector<std::string> strVec;

strVec.push_back("Xyz");
strVec.push_back("abc");


std::sort( strVec.begin(),
strVec.end() ,
LessNoCase() );

std::copy( strVec.begin(),
strVec.end() ,
std::ostream_iterator<std::string>(std::cout,"\n"));

return 0;
}
.



Relevant Pages

  • Re: Report in FM 6 or 7
    ... Please adivse on this- and then, I get to attack this report again in ... you cannot sort by AgeDivision_Category and why the Export/Import ... act they want to be the last act of the show, they have to sort by their ... If the Age Division field contains data in the form "3-5 Age Division" ...
    (comp.databases.filemaker)
  • Re: Report in FM 6 or 7
    ... Please adivse on this- and then, I get to attack this report again in ... you cannot sort by AgeDivision_Category and why the Export/Import ... act they want to be the last act of the show, they have to sort by their ... If the Age Division field contains data in the form "3-5 Age Division" ...
    (comp.databases.filemaker)
  • Re: sort in report
    ... "fredg" wrote: ... date on my report. ... fields I would like to sort on in a report: ... so the format is irrelevant). ...
    (microsoft.public.access.gettingstarted)
  • Re: Report in FM 6 or 7
    ... Please adivse on this- and then, I get to attack this report again in ... you cannot sort by AgeDivision_Category and why the Export/Import ... act they want to be the last act of the show, they have to sort by their ... If the Age Division field contains data in the form "3-5 Age Division" ...
    (comp.databases.filemaker)
  • Re: Sorting Dates
    ... dates to sort properly. ... and grouping expressions used in your report design view. ... Select the overtime hours totals field and Descinding order That is if you ... Then below that select the 'seniority ...
    (microsoft.public.access.reports)

Loading