Update cmap-example
This commit is contained in:
parent
9dad8b81e1
commit
7804fe0d68
1 changed files with 5 additions and 4 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue