Visual Studio Code c++11 extension warning

前端 未结 5 1510
误落风尘
误落风尘 2021-01-11 15:34

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 \

相关标签:
5条回答
  • 2021-01-11 15:50

    In VS Code:

    File>>Preference>>Settings>>Extensions

    find C_Cpp>Default:Cpp Standard drop down menu

    set that to c++11

    Image of Option Window

    0 讨论(0)
  • 2021-01-11 15:56

    I had the same problem, but solved it using set vscode-user-settings <>

    "clang.cxxflags": ["-std=c++14"]
    

    vscode- user setting

    0 讨论(0)
  • 2021-01-11 16:06

    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.

    0 讨论(0)
  • 2021-01-11 16:07

    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.

    0 讨论(0)
  • 2021-01-11 16:10

    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
    
    0 讨论(0)
提交回复
热议问题