gpt4 book ai didi

c++ - 查找 map 中的最后一个条目

转载 作者:行者123 更新时间:2023-11-28 06:13:17 28 4
gpt4 key购买 nike

我有一个

QMap<qreal,int> myMap;

我需要找到最大的键。

这是唯一的方法吗?我希望有一些内置的东西。这够好了吗?为一个简单的操作创建一个迭代器是不是太过分了?

qreal maxkey() 
{
QMap<qreal,int>::iterator it = myMap.end() - 1;
return it.key();
}

编辑 - 我必须使用 4.8

最佳答案

使用lastKey :

const Key & QMap::lastKey() const

Returns a reference to the largest key in the map. This function assumes that the map is not empty.
This executes in logarithmic time.
This function was introduced in Qt 5.2.

如:

qreal last = myMap.lastKey();

关于c++ - 查找 map 中的最后一个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30810780/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com