如何仅使用 int 对该结构进行排序?
struct buch {
string buchtitel;
int preis;
} buch;
最佳答案
如果这是 C++11,您可以使用 lambda 函数。
std::sort
(
beginIter, endIter,
[]( buch const& lhs, buch const& rhs ){ return lhs.preis < rhs.preis; }
);
其中 beginIter
和 endIter
定义您想要排序的项目的随机访问迭代器,endIter
是超出范围末尾的一个.
关于c++ - 对 c 结构进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19703270/