【问题标题】:how to print elements pointed by iterator type list<pair<int,int>>::iterator it如何打印迭代器类型 list<pair<int,int>>::iterator it 指向的元素
【发布时间】:2013-10-26 20:07:40
【问题描述】:

我需要打印列表中每个块对的第二个元素。任何指导将不胜感激请帮助?

【问题讨论】:

  • 我正在遍历列表..
  • 我试过 cout
  • fit-&gt;second; 等同于(*fit).second;

标签: c++ stl iterator


【解决方案1】:

列表中的每个迭代器都指向std::pair&lt;int, int&gt; 类型的对象。为了使用迭代器itr 打印pair 对象中的第二个元素,请执行以下操作:

std::cout << itr->second;

【讨论】:

    猜你喜欢
    • 2018-04-01
    • 2021-02-20
    • 2014-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多