步骤:
1、安装VSCode;
2、在VSCode中安装C++插件
3、安装编译器和配置环境
4、修改VSCode调试配置文件
1、安装VSCode
下载地址:https://code.visualstudio.com/
2、在VSCode中安装C++插件
点击扩展,输入C++,然后点击安装。
3、安装编译器和配置环境
1、下载安装MinGW,下载地址为:https://sourceforge.net/projects/mingw-w64/
2、下载完成后,双击安装,更改默认配置中的Architecture为86_64,为64位,并更改安装路径;
3、在电脑环境变量中添加(\bin;)路径。
4、验证mingw-w64是否配置成功,在cmd中输入:gcc -v
4、修改VSCode调试配置文件
1、新建一个文件夹
备注:安装好vscode会在文档下面默认生成vscode的文件夹,但是在这个文件夹下面可能会有多种语言的代码,所以建议生成对应语言的子文件夹。
2、再新建.vscode文件夹,
3、新建三个配置文件
c_cpp_propertier.json文件
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
"D:/MinGW-W64/mingw64/x86_64-w64-mingw32/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"D:/MinGW-W64/mingw64b/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
"D:/MinGW-W64/mingw64/x86_64-w64-mingw32/include"
]
},
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"compilerPath": "D:\\MinGW-W64\\mingw64\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
新建launch.json,
备注:这个文件的设置和编译环境有关,也表示要写的语言类型
{
"version": "0.2.0",
"configurations": [{
"name": "C++ Launch (GDB)", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
// "launchOptionType": "Local", // 调试器启动类型,这里只能为Local
"targetArchitecture": "x86", // 生成目标架构,一般为x86或x64,可以为x86, arm, arm64, mips, x64, amd64, x86_64
"program": "${file}.exe", // 将要进行调试的程序的路径
"miDebuggerPath": "D:\\MinGW-W64\\mingw64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceRoot}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"preLaunchTask": "g++" // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
}]
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
新建tasks.json
{
"version": "2.0.0",
"command": "g++",
"args": ["-g", "${file}", "-o", "${file}.exe"], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
4、新建test.cpp文件,在这里编写C++代码
5、点击调试F5
更新后
2019.6.25
1、新建一个.vscode文件夹,在文件夹下新建三个json文件;
2、更改launch.json文件,“program”、“externalConsole”、“miDebuggerPath”、“preLaunchTask”四个参数。
3、重启vscode
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": "2.0.0", "configurations": [
{ "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", // "program": "enter program name, for example ${workspaceFolder}/a.exe", "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "E:/MGin/mingw64/bin/gdb.exe", "preLaunchTask": "g++", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ]
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
tasks.json
{
"version": "2.0.0",
"command": "g++",
"args": ["-g", "${file}", "-o", "${fileBasenameNoExtension}.exe"], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c99",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
</div>
<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
<div class="more-toolbox">
<div class="left-toolbox">
<ul class="toolbox-list">
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">点赞</span>
<span class="count"></span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{"mod":"1582594662_002"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打赏开始-->
<!--打赏结束-->
<li class="tool-item tool-more">
<a>
<svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
</a>
<ul class="more-box">
<li class="item"><a class="article-report">文章举报</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="https://blog.csdn.net/JerryZengZ">
<img src="https://profile.csdnimg.cn/8/6/0/3_jerryzengz" class="avatar_pic" username="JerryZengZ">
<img src="https://g.csdnimg.cn/static/user-reg-year/2x/2.png" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="https://blog.csdn.net/JerryZengZ" data-report-click="{"mod":"popu_379"}" target="_blank">JerryZengZ</a></span>
</div>
<div class="text"><span>发布了180 篇原创文章</span> · <span>获赞 9</span> · <span>访问量 9510</span></div>
</div>
<div class="right-message">
<a href="https://im.csdn.net/im/main.html?userName=JerryZengZ" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
</a>
<a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a>
</div>
</div>
</div>