0
Why I get this error ?
Hi, Im wondering why i get this error, and can you please explain what is the porpose of auto x : adj ? Here is the code : #include <iostream> #include <vector> using namespace std; // Add edge void addEdge(vector<int> adj[], int s, int d) { adj[s].push_back(d); adj[d].push_back(s); } void printGraph(vector<int> adj[], int V) { for (int d = 0; d < V; ++d) { cout << "\n Vertex "<< d << ":"; for (auto x : adj[d]) {cout << "-> " << x;} } } int main() { int V = 5; // Create a graph vector<int> adj[V]; // Add edges addEdge(adj, 0, 1); printGraph(adj,V); }
19 Respostas
+ 3
Ovidiu Călin Try this one
#include <iostream>
#include <vector>
using namespace std;
// Add edge
void addEdge(vector<int> adj[], int s, int d) {
adj[s].push_back(d);
adj[d].push_back(s);
}
void printGraph(vector<int> adj[], int V)
{
for (int d = 0; d < V; ++d)
{
cout << "\n Vertex "<< d << ":";
for (unsigned int i = 0; i < adj[d].size(); i++)
{cout << "-> " << adj[d][i];}
}
}
int main() {
int V = 5;
// Create a graph
vector<int> adj[V];
// Add edges
addEdge(adj, 0, 1);
printGraph(adj,V);
return 0;
}
+ 2
try changing auto to int
+ 2
your compiler doesn’t support c++11????
+ 2
Ovidiu Călin Check this link, it should resolve your issue.
https://stackoverflow.com/questions/35723856/need-to-enable-c11-in-codeblocks
+ 1
what is the error?
that prints all the nodes that is connected to d
+ 1
Yes there are no errors, I have also ran it.
+ 1
add
return 0;
at the end of your code
+ 1
THANK YOU
+ 1
+ 1
Worked like a charm
+ 1
Bobby Fischer I am thinking same, his compiler doesn't support C++11 otherwise range-based for loop should have worked.
+ 1
Thanks i'll check it
0
I get x does not name a type
0
Looks like IDE is broken..
0
Now it opens but then crashes..
0
Im using codeblocks mabe find another
0
Same thing
0
I dont know rlly
0
Should i update codeblocks ?