2013-06-05 21:47:54 +00:00
|
|
|
std::map<std::string, int> myDict;
|
|
|
|
|
myDict["hello"] = 1;
|
|
|
|
|
myDict["world"] = 2;
|
|
|
|
|
myDict["!"] = 3;
|
2013-04-10 16:57:12 -07:00
|
|
|
|
2013-06-05 21:47:54 +00:00
|
|
|
// iterating over key-value pairs:
|
2015-02-20 00:35:01 -05:00
|
|
|
for (std::map<std::string, int>::iterator it = myDict.begin(); it != myDict.end(); ++it) {
|
|
|
|
|
// the thing pointed to by the iterator is an std::pair<const std::string, int>&
|
|
|
|
|
const std::string& key = it->first;
|
|
|
|
|
int& value = it->second;
|
2013-06-05 21:47:54 +00:00
|
|
|
std::cout << "key = " << key << ", value = " << value << std::endl;
|
2013-04-10 16:57:12 -07:00
|
|
|
}
|