我正在尝试在下一个循环中使用自动说明符
for (auto x : graf[nod])
{
if (cost + x.second < dist[x.first])
{
dist[x.first] = cost+x.second;
pq.push(make_pair(x.first, dist[x.first]));
}
}
其中graf是成对的向量,似乎在c ++ 98中不起作用,而且我不知道如何将其变成更常见的循环。有什么办法可以避免吗?
您可能会启用C ++ 11
for (auto x : graf[nod])
进入C ++ 03
for (std::size_t i = 0; i != graf[nod].size(); ++i) {
std::pair<T1, T2> x = graf[nod][i];
// ...
}