gpt4 book ai didi

c++ - 如何在 Qmap 中查找特定值

转载 作者:太空狗 更新时间:2023-10-29 23:30:19 24 4
gpt4 key购买 nike

我需要知道 QMap 中的第二个值。 first()last() 等函数是无用的。我必须使用迭代器,某种循环吗?

 QMap<int, QString> map;
map.insert(1, "Mario");
map.insert(2, "Ples");
map.insert(3, "student");
map.insert(4, "grrr");

最佳答案

如果您找到特定的键或值,您可以这样做:

// Returns 1
int key1 = map.key( "Mario" );

// returns "student"
QString value3 = map.value( 3 );

或者您想遍历 QMap 中的所有项目?

关于c++ - 如何在 Qmap 中查找特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25749073/

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