#include#include #include int main() { // Create a QMap with string keys and integer values QMap myMap; // Insert some key-value pairs into the map myMap.insert("apple", 5); myMap.insert("banana", 8); myMap.insert("orange", 3); // Iterate over the map and print out each key-value pair QMap ::const_iterator i; for (i = myMap.constBegin(); i != myMap.constEnd(); ++i) std::cout << i.key().toStdString() << ": " << i.value() << std::endl; return 0; }
#includeIn this example, we create a QMap with string keys and integer values. We then insert several key-value pairs into the map using the `insert` function. Finally, we access the value associated with the "banana" key using the square bracket notation. The QMap class is part of the Qt core library.#include #include int main() { // Create a QMap with string keys and integer values QMap myMap; // Insert some key-value pairs into the map myMap.insert("apple", 5); myMap.insert("banana", 8); myMap.insert("orange", 3); // Access the value associated with a specific key int value = myMap["banana"]; std::cout << "The value associated with 'banana' is " << value << std::endl; return 0; }