根据结构向量中所有结构的每个向量中的第一个单词按字母顺序对结构向量进行排序的最佳方法是什么?
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);