Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我怎样才能只用 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; } );
wherebeginIter并endIter为要排序的项目定义随机访问迭代器,endIter超过范围的末尾。
beginIter
endIter