RosettaCodeData/Task/Associative-array-Iteration/C++/associative-array-iteration-1.cpp

22 lines
393 B
C++
Raw Permalink Normal View History

2013-06-05 21:47:54 +00:00
#include <iostream>
2015-02-20 00:35:01 -05:00
#include <map>
#include <string>
2013-06-05 21:47:54 +00:00
int main() {
2015-02-20 00:35:01 -05:00
std::map<std::string, int> dict {
2013-06-05 21:47:54 +00:00
{"One", 1},
{"Two", 2},
{"Three", 7}
};
dict["Three"] = 3;
std::cout << "One: " << dict["One"] << std::endl;
std::cout << "Key/Value pairs: " << std::endl;
for(auto& kv: dict) {
std::cout << " " << kv.first << ": " << kv.second << std::endl;
}
return 0;
2013-04-10 16:57:12 -07:00
}