#include#include int main() { QMap myMap; // Inserting key-value pairs myMap.insert("John", 25); myMap.insert("Mary", 30); myMap.insert("Bob", 40); // Retrieving values using keys std::cout << "The age of Mary is " << myMap.value("Mary") << std::endl; std::cout << "The age of Bob is " << myMap.value("Bob") << std::endl; return 0; }
The age of Mary is 30 The age of Bob is 40
#include#include int main() { QMap myMap; // Inserting key-value pairs myMap.insert("John", 25); myMap.insert("Mary", 30); myMap.insert("Bob", 40); // Using an iterator to print all key-value pairs QMap ::const_iterator i; for (i = myMap.constBegin(); i != myMap.constEnd(); ++i) { std::cout << i.key().toStdString() << ": " << i.value() << std::endl; } return 0; }
Bob: 40 John: 25 Mary: 30The `QMap` class is a part of the Qt library package, which is a cross-platform application development framework for desktop, mobile, and embedded systems. It provides a wide range of tools and classes for developing UIs, network communication, data storage, and much more.