我有以下内容:
map<boost::tuple<int, string>, int> edges;
edges[boost::make_tuple(1, "a")] = 1;
一个简单的cout << edges[boost::make_tuple(1, "a")] << endl;
确认为1;
我怎样才能迭代这个?以下似乎不起作用:
typedef map<boost::tuple<int, string>, int>::iterator it_type;
for(it_type i = edges.begin(); i != edges.end(); i++) {
cout << i->first << endl;
}
谢谢!
最佳答案
i->first
是一个元组
。因此你不能只是 cout
它。
请参阅 accessing members of boost:: tuple 了解如何访问元组。
您可以使用i->second
,因为它是一个int
,因此您可以使用cout
。
关于c++ - 在 C++ 中迭代 map<boost::tuple<int, string>, int>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16452562/