I am in the process of learning c++ and I\'m using visual studio code for Mac. I use Code Runner to run my program. My problem is that when I use something from c++11 like \
In VS Code:
File>>Preference>>Settings>>Extensions
find C_Cpp>Default:Cpp Standard drop down menu
set that to c++11
I had the same problem, but solved it using set vscode-user-settings <>
"clang.cxxflags": ["-std=c++14"]
I spent so long today trying to figure out why I was getting this error and no where had the exact answer I required so I thought I'd post it here just in case I can save anyone the hassle.
If you're using code runner, look in user settings and set:
"code-runner.executorMap" : { "cpp" : "cd $dir && g++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt" }
The pertinent bit being "g++ -std=c++17".
This is providing of course you can compile your programme in shell using Daniel's solution above but not in VScode + and using code runner.
For everyone who comes to this question to find a quick answer (like I did):
The following compiler command should compile your program main.cpp
with the latest C++ standard (c++17) and should get rid of warning messages like the one described above:
g++ -std=c++17 -g main.cpp -o main
It is mentioned multiple times in the comments, but I think this question should have a regular answer.
I used this to solve my problem. Open your terminal
bash
echo "alias g++='g++ -std=c++17'" >> ~/.bashrc
source ~/.bashrc
zsh
echo "alias g++='g++ -std=c++17'" >> ~/.zshrc
source ~/.zshrc