Compiling C++11 in Visual Studio Code(在 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 标准对其进行编译,这会导致错误.
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++
编译 C++11 程序,当我在我的 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
以便我可以编译程序只需点击 run code
按钮.但是,我找不到一个.如果有其他方法可以编译我的程序,请帮助我.
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: 错误:在 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.
推荐答案
转到设置
> 用户设置
在这里,搜索运行代码配置
:
Go to Settings
> User Settings
In here, search for Run Code Configuration
:
在此菜单下,找到:code-runner.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Visual Studio Code 中编译 C++11


基础教程推荐
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30