【发布时间】:2020-09-27 13:43:47
【问题描述】:
在 Vector 类对象上调用 push_back() 方法时收到以下错误:
error: request for member 'push_back' in 'edges.std::vector<_Tp, _Alloc>::operator[]<int, std::allocator<int> >(((std::vector<int>::size_type)a))', which is of non-class type 'int'
我正在尝试使用邻接列表创建图表,但它不起作用
#include <bits/stdc++.h>
using namespace std;
/****************************************/
/// INPUT / OUTPUT
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
/****************************************/
/// GLOBAL DECLARATIONS
int n, m;
const int nmax = 100005;
vector <int> edges;
/****************************************/
inline void readInput()
{
f >> n >> m;
for(int i = 1 ; i <= m ; ++ i)
{
int a, b;
f >> a >> b;
edges[a].push_back(b);
}
}
int main()
{
readInput();
return 0;
}
抱歉写的不好这是我的第一个问题!
【问题讨论】:
-
请删除所有与您的问题无关的代码并创建一个正确的minimal reproducible example。然后解释你想要达到的目标以及你希望
edges[a].push_back(b);做什么。
标签: c++ arrays compiler-errors