#includeint main() { QHash hash; hash["apple"] = 3; hash["banana"] = 2; hash["orange"] = 2; hash["grape"] = 1; QString key = "orange"; int count = hash.count(key); qDebug() << "The count of" << key << "is" << count; return 0; }
#includeOutput: The count of 2 is 2 Package library: Qt C++ Library.int main() { QHash hash; hash[1] = "apple"; hash[2] = "banana"; hash[3] = "orange"; hash[4] = "apple"; hash[5] = "banana"; int key = 2; int count = hash.count(key); qDebug() << "The count of" << key << "is" << count; return 0; }