在Visual Studio Code中编译C ++ 11 [英] Compiling C++11 in Visual Studio Code

查看:308
本文介绍了在Visual Studio Code中编译C ++ 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio Code编译C ++程序,它适用于大多数C ++程序,因为它使用 g ++ 命令对其进行编译。但是,在使用它编译 c ++ 11 程序时遇到了困难。

I'm using Visual Studio Code to compile C++ programs and it works for most C++ programs as it compiles it using g++ command. However, I am facing difficulty in compiling c++11 programs using it.

当我尝试编译C +时+11个程序,编译器命令 g ++ 尝试使用默认的C ++ 98 Standard对其进行编译,这会导致错误。

When I try compiling C++11 programs, the compiler command g++ tries to compile it using default C++98 Standard and this results in errors.

我知道,使用 g ++ -std = c ++ 11 ,我们可以使用 g ++ ,当我在 cmd 中使用它时,它工作正常,如下:

I am aware that using g++ -std=c++11, we can compile C++11 programs using g++ and it works fine when I use it in my cmd as:


g ++ -std = c ++ 11 some_program.cpp

g++ -std=c++11 some_program.cpp

我希望我可以在Visual Studio Code中调整一些设置并更改编译器从 g ++ g ++ -std = c ++ 11 的命令,这样我只需按运行代码按钮。但是,我找不到一个。如果有其他方法可以编译我的程序,请帮助我。

I wish I could tweak some setting in Visual Studio Code and change the compiler command from g++ to g++ -std=c++11 so that I could compile programs by just hitting the run code button. However, I'm not able to find one. Please help me out if there are alternate ways to get my program compiled.

当前,我收到以下错误消息:

Currently, I'm getting errors as:


some_program.cpp:在函数'int main()':

some_program.cpp: In function 'int main()':

some_program.cpp:12:33:error:in C ++ 98'A'必须由构造函数而不是'{...}'初始化
向量A = {11,2,3,14};

some_program.cpp:12:33: error: in C++98 'A' must be initialized by constructor, not by '{...}' vector A = { 11,2,3,14 };

这些代码片段正确无误,并且已经使用C ++ 11在在线编译器中进行了测试。在这里,它正尝试使用 C ++ 98 进行编译,如错误所示。

The snippets are correct and have been tested with online compilers using C++11. Here, it is trying to compile using C++98 as seen in the error.

推荐答案

转到设置> 用户设置
在这里,搜索运行代码配置

在此菜单下,找到:
代码运行器。 executorMap

通过以下方式将其添加到用户设置中以编辑此设置,以获取C ++ 11支持:

Edit this Setting by adding it to User Setting as below for C++11 support:

"code-runner.executorMap":{
    "cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},

通过将以下设置添加到用户设置中以编辑此设置,以获取C ++ 17支持:

Edit this Setting by adding it to User Setting as below for C++17 support:

"code-runner.executorMap":{
    "cpp": "cd $dir && g++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},

希望这会有所帮助!

这篇关于在Visual Studio Code中编译C ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆