Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 查找地图中的最后一个条目_C++_Qt_Dictionary - Fatal编程技术网

C++ 查找地图中的最后一个条目

C++ 查找地图中的最后一个条目,c++,qt,dictionary,C++,Qt,Dictionary,我有一个 QMap<qreal,int> myMap; QMap-myMap; 我需要找到最大的钥匙 这是唯一的办法吗?我希望可能会有内置的东西。这够好吗?为一个简单的操作创建迭代器不是太多了吗 qreal maxkey() { QMap<qreal,int>::iterator it = myMap.end() - 1; return it.key(); } qreal maxkey() { 迭代器it=myMap.end()-1; 返回它

我有一个

QMap<qreal,int> myMap;
QMap-myMap;
我需要找到最大的钥匙

这是唯一的办法吗?我希望可能会有内置的东西。这够好吗?为一个简单的操作创建迭代器不是太多了吗

qreal maxkey() 
{ 
    QMap<qreal,int>::iterator it = myMap.end() - 1;
    return it.key(); 
}
qreal maxkey()
{ 
迭代器it=myMap.end()-1;
返回它。key();
}
编辑-我必须使用4.8使用:

const Key&QMap::lastKey()const

返回对映射中最大键的引用。此函数假定映射不是空的。
它以对数时间执行。
Qt5.2中引入了此函数

例如:

qreal last = myMap.lastKey();

除了额外的测试之外,你的代码和我的代码有什么不同?哦,我看到了更正。。。这就是我想要的我很抱歉。。。我被迫使用4。8@Thalia然后使用
end()-1
谢谢,我会保留您的信息,以便升级到更高的qt版本。