c++ - 对 c 结构进行排序

标签 c++ c struct

如何仅使用 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; } 
  );

其中 beginIterendIter 定义您想要排序的项目的随机访问迭代器,endIter 是超出范围末尾的一个.

关于c++ - 对 c 结构进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19703270/

相关文章:

c++ - ublas:将 ublas::vector 包装为 ublas::matrix_expression

c - 将 printf 移动到不同的行会产生不同的输出? (C)

C编程按位: value of -1 >> 1

c - 我如何编写一个返回字符串的函数?

C# 结构大小评估

C++ - 从类内部包含 typedef 结构

c++ - VC++ 调试器 - 评估虚函数,CXX0052 : Error: member function not present

c++ - C++调用显式模板构造函数

c++ - 读取文件抛出异常

c# - 使用索引器访问结构?