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); }

30th Jun 2020, 2:59 PM
Ovidiu Călin
Ovidiu Călin - avatar
19 Antworten
+ 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; }
30th Jun 2020, 3:37 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
try changing auto to int
30th Jun 2020, 3:30 PM
Bobby Fischer
Bobby Fischer - avatar
+ 2
your compiler doesn’t support c++11????
30th Jun 2020, 3:42 PM
Bobby Fischer
Bobby Fischer - avatar
30th Jun 2020, 3:47 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
what is the error? that prints all the nodes that is connected to d
30th Jun 2020, 3:25 PM
Bobby Fischer
Bobby Fischer - avatar
+ 1
Yes there are no errors, I have also ran it.
30th Jun 2020, 3:27 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
add return 0; at the end of your code
30th Jun 2020, 3:31 PM
Bobby Fischer
Bobby Fischer - avatar
+ 1
THANK YOU
30th Jun 2020, 3:39 PM
Ovidiu Călin
Ovidiu Călin - avatar
30th Jun 2020, 3:39 PM
Ovidiu Călin
Ovidiu Călin - avatar
+ 1
Worked like a charm
30th Jun 2020, 3:40 PM
Ovidiu Călin
Ovidiu Călin - avatar
+ 1
Bobby Fischer I am thinking same, his compiler doesn't support C++11 otherwise range-based for loop should have worked.
30th Jun 2020, 3:44 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
Thanks i'll check it
30th Jun 2020, 3:48 PM
Ovidiu Călin
Ovidiu Călin - avatar
0
I get x does not name a type
30th Jun 2020, 3:26 PM
Ovidiu Călin
Ovidiu Călin - avatar
0
Looks like IDE is broken..
30th Jun 2020, 3:28 PM
Ovidiu Călin
Ovidiu Călin - avatar
0
Now it opens but then crashes..
30th Jun 2020, 3:31 PM
Ovidiu Călin
Ovidiu Călin - avatar
0
Im using codeblocks mabe find another
30th Jun 2020, 3:31 PM
Ovidiu Călin
Ovidiu Călin - avatar
0
Same thing
30th Jun 2020, 3:32 PM
Ovidiu Călin
Ovidiu Călin - avatar
0
I dont know rlly
30th Jun 2020, 3:43 PM
Ovidiu Călin
Ovidiu Călin - avatar
0
Should i update codeblocks ?
30th Jun 2020, 3:44 PM
Ovidiu Călin
Ovidiu Călin - avatar