#include#include #include int main() { QMap map; map.insert("one", 1); map.insert("two", 2); map.insert("three", 3); QString key = "two"; QMap ::iterator it = map.find(key); // Find the key in the QMap if(it != map.end()) // If found { int value = it.value(); // Get the value associated with the key qDebug() << key << " = " << value; // Print the key-value pair } else { qDebug() << key << " not found!"; } return 0; }
two = 2
#include#include #include int main() { QMap map; map.insert("one", 1); map.insert("two", 2); map.insert("three", 3); if(!map.isEmpty()) { QMap ::const_iterator it = map.constEnd() - 1; // Get the iterator to the last element QString key = it.key(); // Get the key of the last element int value = it.value(); // Get the value of the last element qDebug() << key << " = " << value; // Print the key-value pair } return 0; }
three = 3Package library: QMap is a part of the Qt library, which includes many other C++ classes and tools for building cross-platform applications. It is included in the QtCore library of Qt.