1. 参考/转载

vs code进行c/c++开发

VSCode 的第一个C++程序(windows)[更新2018.10.28]

2. C++开发相关插件(扩展商店中直接搜索)

  • 至少要装C/C++。
  • 还可以安装Code Runner、C++ Intellisense和Include Autocomplete。

3. 编译器

由于VS Code及其各个C++插件都没有C++编译器,所以需要自己装一个然后在项目中配置使用。

  • 常用的有:

    • Windows下的mingw-w64

      • 装sourceforge上的64位的离线安装包!,这个页面链接在官网的下载页面也能找到,其中x86_64是64位系统用的版本,现在我们一般用的是64位系统,所以我们可以在四个x86_64中选一个下载。seh结尾是纯64位编译。sjlj结尾是32 64两种编译,需加-m32或-m64参数。posix通常用于跨平台,比win32兼容性好一些。
      • 官网download表格中的链接的在线安装包在国内一般用不了。
      • 最好将解压后的bin目录路径加到环境变量的末尾,如";C:\MinGW64\bin",当然在VS Code的C++工程中后面生成的launch.json中也可以指定miDebuggerPath为该目录。

4. 开发过程

4.1. 新建工程文件夹并用VS Code打开

4.2. 创建cpp源文件并编码

4.3. 编译

使用ctrl + shift +b编译当前cpp源文件,第一次编译时会提示你配置生成任务"No build task to run found. Configure Build Task...",选择"Create task.json file from template",然后选择"Others"(其他还有MSBuild、Maven、.NET Core),就会生成一个tasks.json文件:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
}
]
}

需要把默认的示例task配置改为编译task配置,因此修改为:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g", //表示在生成的可执行文件中加入调试信息,如果你要调试程序,-g参数必不可少
"-oMySecondCPlus.exe", //编译完成可以看到生成了a.exe文件,这是编译生成的默认文件名称,想要自定义文件名可以使用 -o参数,后面不要有空格
"main.cpp"
],
"presentation": {
"reveal": "never"
},
"problemMatcher": [
"$gcc"
]
}
]
}

再次使用快捷键ctrl + shift +b并选择名为"build"的task就可以编译main.cpp了。

4.4. 调试

选择VS Code左侧的调试界面,最上面的绿色启动按钮旁显示"No Configurations",因此需要点击后添加配置,选择C++(GDB/LLDB),即会生成launch.json文件:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

这里需要修改的配置有:修改gdb编译器路径、修改生成的exe程序路径及名称(默认的a.exe或与task.json中配置的自定义名称相同)、配置每次调试前先进行编译(免得每次都要先手动build生成exe)。

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "D:\\documents\\own\\projects\\MySecondCPlus\\MySecondCPlus.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}

使用VS Code开发C++的更多相关文章

  1. 打造TypeScript的Visual Studio Code开发环境

    打造TypeScript的Visual Studio Code开发环境 本文转自:https://zhuanlan.zhihu.com/p/21611724 作者: 2gua TypeScript是由 ...

  2. 使用VS Code开发调试.NET Core 多项目

    使用Visual Studio Code(VS Code)开发调试.NET Core和ASP.NET Core 多项目multiple project. 之前讲解过如果使用Visual Studio ...

  3. 使用VS Code开发 调试.NET Core 应用程序

    使用VS Code开发 调试.NET Core RC2应用程序,由于.NET Core 目前还处于预览版. 本文使用微软提供的示例进行开发及调试. https://github.com/aspnet/ ...

  4. mac 下配置 VS Code 开发 Golang

    对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github.com/microsoft/vscode-go 这款插件的特性包括: 代码着彩 ...

  5. 使用VS Code开发调试ASP.NET Core 1.0

    使用VS Code开发调试ASP.NET Core 1.0,微软在今天凌晨发布了.NET Core 1.0,ASP.NET Core 1.0 与 Entity Framewok 1.0. 之前跟大家讲 ...

  6. 使用VS Code 开发.NET Core 应用程序 部署到Linux 跨平台

    使用VS Code 开发.NET Core 应用程序 部署到Linux 跨平台. 前面讲解了VSCode开发调试 .NET Core.都只是在windows下运行. .NET Core真正的核心是跨平 ...

  7. 使用VS Code开发ASP.NET Core 应用程序

    最新教程:http://www.cnblogs.com/linezero/p/VSCodeASPNETCore.html 使用VS Code开发ASP.NET Core 应用程序 准备 1.安装VS ...

  8. [Tool] 使用Visual Studio Code开发TypeScript

    [Tool] 使用Visual Studio Code开发TypeScript 注意 依照本篇操作步骤实作,就可以在「Windows」.「OS X」操作系统上,使用Visual Studio Code ...

  9. 使用VS Code开发Angular 2应用程序所需配置文件的解析

    目录 package.json typings.json tsconfig.json launch.json settings.json tasks.json package.json: 这是项目的基 ...

  10. 使用VS Code开发AngularJS 2 第一个应用程序

    使用VS Code开发AngularJS 2 第一个应用程序 目录 运行环境 创建项目 安装依赖包 创建TypeScript应用程序 配置应用程序 运行应用程序 运行环境 运行环境: Windows ...

随机推荐

  1. 杂项-操作系统-百科:Solaris

    ylbtech-杂项-操作系统-百科:Solaris Solaris (读作 /se'laris:/ 或者 /so'le:ris/)是Sun Microsystems研发的计算机操作系统.它被认为是U ...

  2. AJAX验证此ID是否有对应的name

    在表格输入一个ID,然后自动根据ID在数据库中查找是否有对应name 这是javascript部分,利用ajax验证 $(document).ready(function() { $("#c ...

  3. ctf中检测和分离隐藏的文件

    使用binwalk检测是否隐藏了文件 root@sch01ar:~# binwalk '/root/桌面/test.jpg' 还藏了一个zip文件,接下来用foremost来分离文件 root@sch ...

  4. python's twenty-seventh day for me 模

    time模块: 1,计算执行代码的时间 time.time() 2,让程序停这里一段时间 time.sleep(时间(s)) 时间戳时间: import time print(time.time()) ...

  5. AMF解析之数据类型定义 (转)

    目录(?)[-] OpenRTMFPCumulus Primer15AMF解析之数据类型定义 数据类型 undefined Type null Type false type true type in ...

  6. 24-从零玩转JavaWeb-包装类、自动装箱、自动拆箱

    一.什么是包装类 二.对基本数据类型包装的好处 三.装箱操作 四.拆箱操作 五.自动装箱 六.自动拆箱 七.字符串与基本数据类型和包装类的转换   八.包装类的缓存设计

  7. 如何在Less中使用使用calc

    文章转载自  琼台博客:http://www.qttc.net/201409448.html Less的好处不用说大家都知道,确实让写CSS的人不在痛苦了,最近我在Less里加入calc时确发现了有点 ...

  8. 通过class类获取类的成员变量和构造函数信息

  9. 【COCI2012】覆盖字符串

    [题目描述] 给出一个长度为N的小写字母串,现在Mirko有M个若干长度为Li字符串.现在Mirko要用这M个字符串去覆盖给出的那个字符串的.覆盖时,必须保证:1.Mirko的字符串不能拆开,旋转:2 ...

  10. SpringCloud02 Eureka知识点、Eureka服务端和客户端的创建、Eureka服务端集群、Eureka客户端向集群的Eureka服务端注册

    1 Eureka知识点 按照功能划分: Eureka由Eureka服务端和Eureka客户端组成 按照角色划分: Eureka由Eureka Server.Service Provider.Servi ...