Visual Studio Code c++11 extension warning












2















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 "auto" for variable declaration, visual studio code gives me a warning like this, but if I try running it on Xcode or Eclipse it doesn't:



warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for(auto y: nstrVec)


This is the program if it's necessary:



#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <numeric>
#include <sstream>

int main(){

std::vector<std::string> nstrVec(10);

std::string str("I'm a string");
nstrVec[0] = str;

std::cout << str.at(0) << "n";
std::cout << str.front() << " " << str.back() << "n";
std::cout << "Length " << str.length() << "n";
// copies all characters after the fourth
std::string str2(str, 4);

for(auto y: nstrVec)
if(y != "")
std::cout << y << "n";

return 0;
}


And this is the c_cpp_proprerties.json file:



{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/System/Library/Frameworks/Kernel.framework/Versions/A/Headers"
],
"defines": ,
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}









share|improve this question

























  • Are you compiling for C++11? It doesn't sound like it. The auto keyword was introduced in C++11 so before that it was considered a language extension by Visual Studio.

    – CoryKramer
    Jun 26 '18 at 15:46











  • @CoryKramer Question is about VS Code, not VS.

    – Neil Butterworth
    Jun 26 '18 at 15:47











  • You are telling the compiler to use 2 different standards: you have both "-std=c++17" and "-std=c++11".

    – Fabio Turati
    Jun 26 '18 at 15:47






  • 2





    Can you compile it from the command line? That is, open a shell, go to that directory, and type g++ -std=c++17 -g helloworld.cpp -o helloworld: does it work?

    – Fabio Turati
    Jun 26 '18 at 16:14






  • 2





    I'm glad that you could solve your problem, but please do not edit your post to add "SOLVED" in the title, Stack Overflow works differently. The correct way to indicate it is to accept an answer, once there is one. You could ask @Bob__ whether he is interested in posting one; if he isn't, please post it yourself and accept it. Thank you!

    – Fabio Turati
    Jun 26 '18 at 22:10
















2















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 "auto" for variable declaration, visual studio code gives me a warning like this, but if I try running it on Xcode or Eclipse it doesn't:



warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for(auto y: nstrVec)


This is the program if it's necessary:



#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <numeric>
#include <sstream>

int main(){

std::vector<std::string> nstrVec(10);

std::string str("I'm a string");
nstrVec[0] = str;

std::cout << str.at(0) << "n";
std::cout << str.front() << " " << str.back() << "n";
std::cout << "Length " << str.length() << "n";
// copies all characters after the fourth
std::string str2(str, 4);

for(auto y: nstrVec)
if(y != "")
std::cout << y << "n";

return 0;
}


And this is the c_cpp_proprerties.json file:



{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/System/Library/Frameworks/Kernel.framework/Versions/A/Headers"
],
"defines": ,
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}









share|improve this question

























  • Are you compiling for C++11? It doesn't sound like it. The auto keyword was introduced in C++11 so before that it was considered a language extension by Visual Studio.

    – CoryKramer
    Jun 26 '18 at 15:46











  • @CoryKramer Question is about VS Code, not VS.

    – Neil Butterworth
    Jun 26 '18 at 15:47











  • You are telling the compiler to use 2 different standards: you have both "-std=c++17" and "-std=c++11".

    – Fabio Turati
    Jun 26 '18 at 15:47






  • 2





    Can you compile it from the command line? That is, open a shell, go to that directory, and type g++ -std=c++17 -g helloworld.cpp -o helloworld: does it work?

    – Fabio Turati
    Jun 26 '18 at 16:14






  • 2





    I'm glad that you could solve your problem, but please do not edit your post to add "SOLVED" in the title, Stack Overflow works differently. The correct way to indicate it is to accept an answer, once there is one. You could ask @Bob__ whether he is interested in posting one; if he isn't, please post it yourself and accept it. Thank you!

    – Fabio Turati
    Jun 26 '18 at 22:10














2












2








2








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 "auto" for variable declaration, visual studio code gives me a warning like this, but if I try running it on Xcode or Eclipse it doesn't:



warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for(auto y: nstrVec)


This is the program if it's necessary:



#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <numeric>
#include <sstream>

int main(){

std::vector<std::string> nstrVec(10);

std::string str("I'm a string");
nstrVec[0] = str;

std::cout << str.at(0) << "n";
std::cout << str.front() << " " << str.back() << "n";
std::cout << "Length " << str.length() << "n";
// copies all characters after the fourth
std::string str2(str, 4);

for(auto y: nstrVec)
if(y != "")
std::cout << y << "n";

return 0;
}


And this is the c_cpp_proprerties.json file:



{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/System/Library/Frameworks/Kernel.framework/Versions/A/Headers"
],
"defines": ,
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}









share|improve this question
















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 "auto" for variable declaration, visual studio code gives me a warning like this, but if I try running it on Xcode or Eclipse it doesn't:



warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for(auto y: nstrVec)


This is the program if it's necessary:



#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <numeric>
#include <sstream>

int main(){

std::vector<std::string> nstrVec(10);

std::string str("I'm a string");
nstrVec[0] = str;

std::cout << str.at(0) << "n";
std::cout << str.front() << " " << str.back() << "n";
std::cout << "Length " << str.length() << "n";
// copies all characters after the fourth
std::string str2(str, 4);

for(auto y: nstrVec)
if(y != "")
std::cout << y << "n";

return 0;
}


And this is the c_cpp_proprerties.json file:



{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/System/Library/Frameworks/Kernel.framework/Versions/A/Headers"
],
"defines": ,
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}






c++ macos visual-studio-code






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 8 '18 at 3:08









Cœur

17.6k9104145




17.6k9104145










asked Jun 26 '18 at 15:43









BONANDRINI CARLOBONANDRINI CARLO

306




306













  • Are you compiling for C++11? It doesn't sound like it. The auto keyword was introduced in C++11 so before that it was considered a language extension by Visual Studio.

    – CoryKramer
    Jun 26 '18 at 15:46











  • @CoryKramer Question is about VS Code, not VS.

    – Neil Butterworth
    Jun 26 '18 at 15:47











  • You are telling the compiler to use 2 different standards: you have both "-std=c++17" and "-std=c++11".

    – Fabio Turati
    Jun 26 '18 at 15:47






  • 2





    Can you compile it from the command line? That is, open a shell, go to that directory, and type g++ -std=c++17 -g helloworld.cpp -o helloworld: does it work?

    – Fabio Turati
    Jun 26 '18 at 16:14






  • 2





    I'm glad that you could solve your problem, but please do not edit your post to add "SOLVED" in the title, Stack Overflow works differently. The correct way to indicate it is to accept an answer, once there is one. You could ask @Bob__ whether he is interested in posting one; if he isn't, please post it yourself and accept it. Thank you!

    – Fabio Turati
    Jun 26 '18 at 22:10



















  • Are you compiling for C++11? It doesn't sound like it. The auto keyword was introduced in C++11 so before that it was considered a language extension by Visual Studio.

    – CoryKramer
    Jun 26 '18 at 15:46











  • @CoryKramer Question is about VS Code, not VS.

    – Neil Butterworth
    Jun 26 '18 at 15:47











  • You are telling the compiler to use 2 different standards: you have both "-std=c++17" and "-std=c++11".

    – Fabio Turati
    Jun 26 '18 at 15:47






  • 2





    Can you compile it from the command line? That is, open a shell, go to that directory, and type g++ -std=c++17 -g helloworld.cpp -o helloworld: does it work?

    – Fabio Turati
    Jun 26 '18 at 16:14






  • 2





    I'm glad that you could solve your problem, but please do not edit your post to add "SOLVED" in the title, Stack Overflow works differently. The correct way to indicate it is to accept an answer, once there is one. You could ask @Bob__ whether he is interested in posting one; if he isn't, please post it yourself and accept it. Thank you!

    – Fabio Turati
    Jun 26 '18 at 22:10

















Are you compiling for C++11? It doesn't sound like it. The auto keyword was introduced in C++11 so before that it was considered a language extension by Visual Studio.

– CoryKramer
Jun 26 '18 at 15:46





Are you compiling for C++11? It doesn't sound like it. The auto keyword was introduced in C++11 so before that it was considered a language extension by Visual Studio.

– CoryKramer
Jun 26 '18 at 15:46













@CoryKramer Question is about VS Code, not VS.

– Neil Butterworth
Jun 26 '18 at 15:47





@CoryKramer Question is about VS Code, not VS.

– Neil Butterworth
Jun 26 '18 at 15:47













You are telling the compiler to use 2 different standards: you have both "-std=c++17" and "-std=c++11".

– Fabio Turati
Jun 26 '18 at 15:47





You are telling the compiler to use 2 different standards: you have both "-std=c++17" and "-std=c++11".

– Fabio Turati
Jun 26 '18 at 15:47




2




2





Can you compile it from the command line? That is, open a shell, go to that directory, and type g++ -std=c++17 -g helloworld.cpp -o helloworld: does it work?

– Fabio Turati
Jun 26 '18 at 16:14





Can you compile it from the command line? That is, open a shell, go to that directory, and type g++ -std=c++17 -g helloworld.cpp -o helloworld: does it work?

– Fabio Turati
Jun 26 '18 at 16:14




2




2





I'm glad that you could solve your problem, but please do not edit your post to add "SOLVED" in the title, Stack Overflow works differently. The correct way to indicate it is to accept an answer, once there is one. You could ask @Bob__ whether he is interested in posting one; if he isn't, please post it yourself and accept it. Thank you!

– Fabio Turati
Jun 26 '18 at 22:10





I'm glad that you could solve your problem, but please do not edit your post to add "SOLVED" in the title, Stack Overflow works differently. The correct way to indicate it is to accept an answer, once there is one. You could ask @Bob__ whether he is interested in posting one; if he isn't, please post it yourself and accept it. Thank you!

– Fabio Turati
Jun 26 '18 at 22:10












2 Answers
2






active

oldest

votes


















2














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



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


vscode- user setting






share|improve this answer

































    1














    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.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51046803%2fvisual-studio-code-c11-extension-warning%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














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



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


      vscode- user setting






      share|improve this answer






























        2














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



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


        vscode- user setting






        share|improve this answer




























          2












          2








          2







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



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


          vscode- user setting






          share|improve this answer















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



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


          vscode- user setting







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 7:20









          Filnor

          1,15021624




          1,15021624










          answered Nov 22 '18 at 7:02









          vic.zhangvic.zhang

          214




          214

























              1














              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.






              share|improve this answer




























                1














                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.






                share|improve this answer


























                  1












                  1








                  1







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 15 '18 at 20:16









                  Daniel SchuetteDaniel Schuette

                  150112




                  150112






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51046803%2fvisual-studio-code-c11-extension-warning%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      Refactoring coordinates for Minecraft Pi buildings written in Python