c++ - 如何打印具有元素集的多重图

标签 c++ stl set multimap

我正在使用以下结构的多重映射:

typedef std::pair <set <int> , char> trigger;
std::multimap <trigger , set <int> > transitions;

模拟确定性有限自动机的转换函数,以便从一组状态通过读取符号进入另一组状态。 我如何打印这个 multimap ? 我这样试过:

for (std::multimap<trigger,set<int> >::iterator it=transitions.begin(); it!=transitions.end(); ++it)
    {
    for (std::set<int>::iterator its=it.first.first.begin(); its!=it.first.first.end(); ++its)
    std::cout << *its<<" ";
    std::cout<<(*it).first.second<<endl;
    for (std::set<int>::iterator its=it.second.begin(); its!=it.second.end(); ++its)
    std::cout << *its<<" ";
    }

但是它说 multimap 没有名为 first 或 second 的成员。 提前致谢。

最佳答案

这些行的问题

for (std::set<int>::iterator its=it.first.first.begin(); its!=it.first.first.end(); ++its)

for (std::set<int>::iterator its=it.second.begin(); its!=it.second.end(); ++its)

是迭代器。使用 -> 访问它的值。

for (std::set<int>::iterator its=it->first.first.begin(); its!=it->first.first.end(); ++its)

for (std::set<int>::iterator its=it->second.begin(); its!=it->second.end(); ++its)

关于c++ - 如何打印具有元素集的多重图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29329302/

相关文章:

c++ - 删除STL指针 vector 条目的快速方法

c++ - 从 vector 生成元组(通用算法)

c++ - 有没有办法在 C++ 中预定义 std::set 大小?

python - 遍历一组字典 - python - 基本搜索

c++ - 在 C++ 中将一维数组作为二维数组访问

c++ - 一般产品中的特征自动类型推导

c++ - GNU Linker 找不到本地共享库

c++ - GCC 中的循环展开行为

c++ - STL 列表迭代器错误

java - 使用 HashMap 获取重复出现的情况