c++ - 在 C++ 中迭代 map<boost::tuple<int, string>, int>

标签 c++ boost dictionary iterator tuples

我有以下内容:

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/

相关文章:

不允许使用 C++ 数据成员初始值设定项

c++ - 如何让 boost json 使用正确的数据类型

c++ - 如何为具有共享指针的结构的多索引制作修饰符以 boost 记录器后端以重置此后端?

java - 如何从 map 中为每个数据中心打印随机主机?

python - 将 DataFrame 转换为字典,其中标题为键,列为带有值的数组

python - 将字符串转换为字典列表 Python3

c++ - 如何允许嵌入式 Python 解释器中调用的脚本导入 3rd 方库?

c++ - 多态指针

c++ - 如何测试特定的 C++ 语句是否比其他语句快或慢?

c++ - Boost Circular Buffer,如何让它在填充时调用一些函数?