vector <pair<int,int> > a[4]
.I的矢量的陣列已經添加元素使用它push_back.But我不知道如何打印我使用iteretor的elements.if和打印像[I]至.first或a [i] .second它會引發錯誤。執行此操作的其他方法。提前感謝。
vector <pair<int,int> > a[4];
for(int i = 0;i < e;++i)
{
int x,y;
cin >> x >> y >> w;
a[x].push_back({w, y});
a[y].push_back({w, x});
}
這是我如何推送elements.But如何打印它們。
for(i=a[i].begin();i!=a[i].end();i++)
{
cout<<a[i].second<<" ";
}
我正在以下error.I硝基甲苯知道如何打印。
error: no match for 'operator[]' (operand types are 'std::vector<std::pair<int, int> >*' and 'std::vector<std::pair<int, int> >::iterator {aka __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >}')
for(i=g[i].begin();i!=g[i].end();i++)
歡迎來到Stack Overflow。請花些時間閱讀[The Tour](http://stackoverflow.com/tour),並參閱[幫助中心](http://stackoverflow.com/help/asking)中的資料,瞭解您可以在這裏問。 –
爲什麼這是我不應該問的話題? – piku
你確定要有一個'vector>'的數組嗎? –