jeudi 11 mars 2021

How to change the C++ version in VS Code? [duplicate]

I am using for each loop but vs code, the terminal is giving error because it is supported by a specific version of C++, Now how to change the supported c++ version for vs code

#include<bits/stdc++.h>
using namespace std;

void BFS(vector<int> adj[], int s, bool visited[])
{
    queue<int> q;

    visited[s] = true;
    q.push(s);

    while(q.empty()==false)
    {
        int u = q.front();
        q.pop();

        for(int v:adj[u]){
            if(visited[v]==false){
                visited[v] =true;
                q.push(v);
            }
        }
    }
}

int BFSDin(vector<int> adj[], int V){
    bool visited[V];
    int count = 0;
    for(int i=0; i<V;i++)
    {
        visited[i] =false;
    }

    for(int i=0; i<V;i++)
    {
        if(visited[i]==false)
        {
            BFS(adj, i,  visited);
            count++;
        }
    }
    return count;
}

void addEdge(vector<int> adj[], int u, int v){
    adj[u].push_back(v);
    adj[v].push_back(u);
}

int main()
{
    int V=7;
    vector<int> adj[V];
    addEdge(adj,0,1); 
    addEdge(adj,0,2); 
    addEdge(adj,2,3); 
    addEdge(adj,1,3); 
    addEdge(adj,4,5);
    addEdge(adj,5,6);
    addEdge(adj,4,6);

    cout << "Number of islands: "<<BFSDin(adj,V); 

    return 0; 

}

Output:

In function void BFS(std::vector<int>*, int, bool*):

warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11 for(int v:adj[u]){

Segmentation fault (core dumped)

Aucun commentaire:

Enregistrer un commentaire