1
我有一個類,我想用來排序我的字符串,布爾對矢量。我的字符串是utf-8編碼的。我想對它們進行排序,這樣,如果人的區域設置爲例如,法國,我希望的是,如果用戶鍵入:幫助使用std :: locale?
zap
apple
école
blue
erable
,這將挑選出是:
apple
blue
école
erable
zap
我的std :: Locale類是這樣的:
class AguiLBLocaleCompare :
public std::binary_function<std::pair<std::string, bool>,
std::pair<std::string,bool>, bool> {
protected:
const std::collate<char> &coll;
public:
AguiLBLocaleCompare(std::locale loc)
: coll(std::use_facet<std::collate<char> >(loc)) {}
bool operator()(const std::pair<std::string, bool> &a,
const std::pair<std::string, bool> &b) const {
// std::collate::compare() takes C-style string (begin, end)s and
// returns values like strcmp or strcoll. Compare to 0 for results
// expected for a less<>-style comparator.
return coll.compare(a.first.c_str(), a.first.c_str() + a.first.size(),
b.first.c_str(), b.first.c_str() + b.first.size()) < 0;
}
};
,然後我的項目排序方法是:
void AguiListBox::sort()
{
if(!isReverseSorted())
std::sort(items.begin(),items.end(),AguiLBLocaleCompare(WHAT_DO_I_PUT_HERE));
else
std::sort(items.rbegin(),items.rend(),AguiLBLocaleCompare(WHAT_DO_I_PUT_HERE));
}
所以我不知道要在構造函數中放什麼才能達到預期的效果。
我試過std::locale()
,但是它在zap中的z之後排序了口音,這不是我想要的。
項目是
std::vector<std::pair<std::string, bool>>
感謝
你在哪個平臺上? C++語言環境支持出了名的錯誤。 – 2011-01-06 18:21:45