如何通过迭代器访问向量中的嵌套对?

Posted

技术标签:

【中文标题】如何通过迭代器访问向量中的嵌套对?【英文标题】:how can I acces nested pair in a vector by iterator? 【发布时间】:2018-05-19 14:57:33 【问题描述】:

我正在尝试通过迭代器访问向量中的嵌套对,但在代码块 IDE 中出现错误,请帮助我如何做到这一点?你可以在附图中看到我的代码。

#include<bits/stdc++.h>
using namestace std;

vector<pair<int , pair<int, bool> > > graph[1000000];
vector<pair<int , pair<int, bool> > >:: iterator it;

queue<int> Q;
int cost[1000000], visit[1000000];


void BFS(int s)

    Q.push(s)
    visit[s] = 1;
    while(!Q.empty() 
        int v = Q.front();
        Q.pop();
        for (it=graph[v].begin(); it != graph[v].end(); it++) 
            if(cost[it->first] == -1) 
                cost[it->first] = it->second->first + cost[v];
                Q.push(it->first);

            

【问题讨论】:

欢迎来到 ***.com。请花一些时间阅读the help pages,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。也请take the tour 和read about how to ask good questions。最后请学习如何创建Minimal, Complete, and Verifiable Example。 【参考方案1】:
it->first.second

因为它是一个指针,但它指向的对是对本身,而不是指针。

【讨论】:

以上是关于如何通过迭代器访问向量中的嵌套对?的主要内容,如果未能解决你的问题,请参考以下文章