Update cmap-example

This commit is contained in:
pudepiedj 2023-10-05 12:31:10 +01:00
parent 9dad8b81e1
commit 7804fe0d68

View file

@ -2,17 +2,18 @@
// there are two: std::map automatically sorts on key; std::unordered_map does not
#include <map>
#include <string>
int main() {
std::map<std::string, int> dict;
dict["apple"] = 5;
dict["banana"] = 2;
dict["orange"] = 7;
dict[std::string("apple")] = 5;
dict[std::string("banana")] = 2;
dict[std::string("orange")] = 7;
// Accessing elements in the map
printf("Value of apple: %d\n", dict["apple"]);
printf("Value of apple: %d\n", dict[std::string("apple")]);
for (const auto& pair : dict) {
printf("Key: %s, Value: $s\n", pair.first, pair.second);