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.
I don't use mac but you can try the following code
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.
Update tasks.json to -> { "type": "shell", "label": "g++ build active file", "command": "/usr/bin/g++", "args": [ "-std=c++11", "-g", "$$${file}", "-o", "$$${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "/usr/bin" } }
then,
Open Visual Studio Code.
Click on the Extensions view icon on the sidebar or use the keyboard shortcut (Ctrl+Shift+X on Windows and Linux, ⇧⌘X on macOS).
In the Extensions view search bar, type ‘C++’.
Click on the C/C++ extension (ms-vscode.cpptools).
To the right of Uninstall, there should be a gear icon. Click it and select Extension Settings from the dropdown menu.
In the search bar of the settings page, type cppStandard. You should see an option for Cpp Standard. Change it to your desired version. For example, if you want to use C++17, select c++17.
Heap sent me this.
Hi bro, I am facing the exact issue.
newcode.cpp:38:17: error: non-aggregate type 'vector' cannot be initialized with an initializer list vector arr = {1,2,3,4,5};
kindly let me know the detailed solution about this. I will be very very much thankful to you.
https://stackoverflow.com/questions/39022787/error-non-aggregate-type-vectorint-cannot-be-initialized-with-an-initialize