タイトルが言ったように、私はテストのデモを書いたstd :: sort()compare関数で "return lhs.size()== rhs.size()"を使用できないのはなぜですか?
bool comp(string lhs, string rhs) {
return lhs.size() < rhs.size();
}
bool comp1(string lhs, string rhs) {
return lhs.size() == rhs.size();
}
int main(int argc, const char *argv[]) {
string str[] = {"dog", "is", "cat", "elephant", "fish", "cow"};
std::sort(str, str + 6, comp1);
output();
}
出力:期待cat dog is elephant fish cow
:何、...cat dog cow...
は、私が一緒に、同じ大きさの文字列を入れたいが、それは動作しませんでしたが問題?
https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings – LogicStuff
受信した出力は何ですか? –
「同じサイズの文字列をまとめて」とはどういう意味ですか?あなたの最初の 'comp'関数を使ってソートしていないのですか? – Jezor