The problem I'm having is that I need to sort a whole bunch of char pointers, but they have special characters. I managed to get a sorting procedure like so:
std::sort(dict_.begin(), dict_.end(), comp);
bool comp(NumPair& a, NumPair& b)
{
return boost::lexicographic_compare(a.pFirst, b.pFirst);
}
This worked great, except that all special german characters were sorted before all the others. My teacher (yes, this is pertaining to a homework assignment), however, wants them to be sorted at the end. Awesome!
So I was playing around and thought I could use a trick I saw on a website to enable a regional locale to include the special characters like so
return boost::lexicographic_compare(a.pFirst, b.pFirst, locale("german"));
Didn't work! So:
bool comp()
{
setlocale(LC_ALL, "");
return boost::lexicographic_compare(a.pFirst, b.pFirst);
}
Didn't work!
If you have them, I would love to hear some other ideas that might actually work.
Update:
As requested, some sample input and output:
// Some entries
dict_.push_back( NumPair ( "öffnen", "to open" ) );
dict_.push_back( NumPair ( "überraschen", "to surprise" ) );
dict_.push_back( NumPair ( "wünschen", "to wish, to desire, to want" ) );
dict_.push_back( NumPair ( "widersprechen", "to contradict_" ) );
// NumPair ctor.
NumPair( const char *pFirst, const char *pSecond )
{
/* Deep copy of pFirst and pSecond */
}
Output after result:
öffnen
überraschen
wünschen
widersprechen