"#include "QList"\n#include "QDebug"\n\nint main() {\n QList list;\n list << 1 << 2 << 3 << 2 << 4 << 2 << 5;\n\n int index = 2;\n int count = list.count(list.at(index));\n\n qDebug() << "Element at index" << index << "occurs" << count << "times";\n\n return 0;\n}\n"\n\n运行结果为:\n\n"Element at index 2 occurs 3 times"\n\n在上述示例中,我们创建了一个包含一些整数的QList。然后,我们指定了要查找的元素的索引(这里是2),并使用count函数来计算该元素在列表中出现的次数。最后,我们使用qDebug输出结果。

Qt QList<int> 查找指定索引元素出现次数 - 示例代码

原文地址: https://www.cveoy.top/t/topic/p1bz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录