#include#include int main() { QMap myMap; myMap.insert("apple", 2); myMap.insert("banana", 3); myMap.erase("banana"); // myMap now contains only one key-value pair return 0; }
#includeIn this example, we created a QMap instance called myMap, which stores string keys and integer values. We added two key-value pairs to myMap using the insert() function. Finally, we removed all key-value pairs from myMap by calling the clear() function. The QMap class is part of the Qt Library.#include int main() { QMap myMap; myMap.insert("apple", 2); myMap.insert("banana", 3); myMap.clear(); // myMap is now empty return 0; }