構造のベクトル内のすべての構造のすべてのベクトルの最初の単語に基づいて構造のベクトルをアルファベット順に並べ替える最良の方法は何ですか?
struct sentence{
vector<string> words;
};
vector<sentence> allSentences;
言い換えれば、words [0]に基づいてallSentencesをソートする方法は?
編集:私は次の解決策を使用しました:
bool cmp(const sentence& lhs, const sentence & rhs)
{
return lhs.words[0] < rhs.words[0];
}
std::sort(allSentences.begin(), allSentences.end(), cmp);