#include#include int main() { QMap map; map.insert("Alice", 25); map.insert("Bob", 30); map.insert("Charlie", 35); QMap ::const_iterator it = map.constFind("Bob"); if (it != map.constEnd()) { qDebug() << "Bob's age is" << *it; } return 0; }
#includeIn this example, we create a QMap object with string keys and string values that represent email addresses. We insert three key-value pairs into the map, and then use constFind to obtain a constant iterator to the element with the key "Dave". Since "Dave" was not found in the map, constFind returns the constant end iterator of the map, and we output a message stating that "Dave" was not found. The QMap class is part of the Qt Core module, which is part of the Qt Toolkit.#include int main() { QMap map; map.insert("Alice", "[email protected]"); map.insert("Bob", "[email protected]"); map.insert("Charlie", "[email protected]"); QMap ::const_iterator it = map.constFind("Dave"); if (it == map.constEnd()) { qDebug() << "Dave not found in map"; } return 0; }