#include <iostream>
#include <map>
#include <utility>
#include <string>
int main()
{
std::map<std::string, std::map<int, std::string> > ssi;
ssi["123"].insert(std::map<int, std::string>::value_type(1, "abc"));
ssi["123"].insert(std::map<int, std::string>::value_type(2, "def"));
ssi["456"].insert(std::map<int, std::string>::value_type(1, "ghi"));
ssi["456"].insert(std::map<int, std::string>::value_type(2, "jkl"));
// key1で検索
std::map<std::string, std::map<int, std::string> >::const_iterator pos1;
std::map<int, std::string>::const_iterator pos2;
for (pos1 = ssi.begin(); pos1 != ssi.end(); ++pos1)
if (pos1->first == "456")
for (pos2 = pos1->second.begin(); pos2 != pos1->second.end(); ++pos2)
std::cout << "key2: first = " << pos2->first << ", second = " << pos2->second << std::endl;
// key2で検索
for (pos1 = ssi.begin(); pos1 != ssi.end(); ++pos1)
for (pos2 = pos1->second.begin(); pos2 != pos1->second.end(); ++pos2)
if (pos2->first == 2)
std::cout << "key1 = " << pos1->first << ", key2: second = " << pos2->second << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPHN0cmluZz4KCmludCBtYWluKCkKewogIHN0ZDo6bWFwPHN0ZDo6c3RyaW5nLCBzdGQ6Om1hcDxpbnQsIHN0ZDo6c3RyaW5nPiA+IHNzaTsKICAKICBzc2lbIjEyMyJdLmluc2VydChzdGQ6Om1hcDxpbnQsIHN0ZDo6c3RyaW5nPjo6dmFsdWVfdHlwZSgxLCAiYWJjIikpOwogIHNzaVsiMTIzIl0uaW5zZXJ0KHN0ZDo6bWFwPGludCwgc3RkOjpzdHJpbmc+Ojp2YWx1ZV90eXBlKDIsICJkZWYiKSk7CiAgc3NpWyI0NTYiXS5pbnNlcnQoc3RkOjptYXA8aW50LCBzdGQ6OnN0cmluZz46OnZhbHVlX3R5cGUoMSwgImdoaSIpKTsKICBzc2lbIjQ1NiJdLmluc2VydChzdGQ6Om1hcDxpbnQsIHN0ZDo6c3Rya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