【发布时间】:2016-02-12 10:23:56
【问题描述】:
我有一个unordered_set,叫做方程式。我不是要排序或 qsort 是,这是我正在运行的代码行:
qsort(&equations, equations.size(), sizeof(string), strcmp);
我得到的错误是:
error: cannot convert 'std::unordered_set<std::basic_string<char> >' to 'void*'
for argument '1' to 'void qsort(void*, size_t, size_t, __compar_fn_t)'
qsort(equations, equations.size(), sizeof(string), strcmp);
【问题讨论】:
-
A)
unordered_set无法排序。您需要将其内容复制到例如vector,或使用带有您自己的排序标准的std::set。 B)qsort是一个 C 函数。它不会理解如何处理用户定义的类型,例如 C++ 容器。你可能想要std::sort。 -
排序的语法是什么? @juanchopanza
-
查一下。这里有大约 200 亿个问题。
标签: c++ sorting qsort unordered-set