Hawkwatch_19's blog

By Hawkwatch_19, history, 2 weeks ago, In English

Help me to fix this problem.

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

int main() {
    vector<int> dir = {1,2,3};
    for (auto d : dir)
    {
        cout<<d<<endl;
    }
    return 0;
}

Whenever I try to run this code in vscode I got this error =>

Is there anyone who ever faced this problem(in mac) and solved it. plz help me. It would be a great relief for me.

Thanks in advance <3.

  • Vote: I like it
  • +9
  • Vote: I do not like it

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I don't use mac but you can try the following code

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

int main()
{
    int a[3] = {1, 2, 3};
    vector<int> dir(a, a + 3);
    for (auto d : dir)
    {
        cout << d << endl;
    }
    return 0;
}
  • »
    »
    2 weeks ago, # ^ |
    Rev. 4   Vote: I like it +16 Vote: I do not like it

    It had been solved already by Heap_OverFlow, but comment got removed due to some reason? Possibly, Heap_OverFlow reported some cheater, who reported heap's comments.

    The soln that heap said and worked with the OP had been

    updating the C++ standard in VS Code to C++11 or later, where the initializer list is supported.

    Modify tasks.json to include the -std=c++11 flag (or a later version like -std=c++14, -std=c++17, etc.) when compiling your code.

    Spoiler
    I wonder if cheat reporting these days lead to removal of such useful comments solving people's doubts?