我的电脑本来装有vs2015,本人太懒,喜欢极简主义,vs太大打开不方便,就想用一个轻量级的编辑器,无奈用vs自带的msvc怎么都配置不成功(知道的小伙伴还请指导),经历了痛苦的各种搜索,还是选择了mingw作为编译器,最终才配成。
万恶的痛苦之源主要的操作跟官网的教程差不多,下边主要说一些特殊的地方
官网教程:https://code.visualstudio.com/docs/cpp/config-mingw
1.下载mingw可以选择x86-64,而不是默认的
2.创建好文件以后,一定要先编译即shift+ctrl+B,看到文件夹下边有.exe文件,然后再按F5
3.或者可以用run code先运行
测试文件如下:
https://download.csdn.net/download/Meet_csdn/12005908
下边放上匹配值的json文件
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": "${workspaceFolder}/helloworld.exe",
//更好用的语句,换程序名字也不用改代码
//"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json版本一
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": ["-g", "-o", "helloworld", "helloworld.cpp"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
版本二(更加具有普适性,更推荐)
{
"version": "2.0.0",
"tasks": [
{
"label": "(gdb) Launch", // 任务名称,与launch.json的preLaunchTask相对应
"command": "g++", // 要使用的编译器
"args": [
"${file}",
"-o", // 指定输出文件名,不加该参数则默认输出a.exe
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g", // 生成和调试有关的信息
], // 编译命令参数
"type": "shell",
"group": {
"kind": "build",
"isDefault": true // 设为false可做到一个tasks.json配置多个编译指令,需要自己修改本文件,我这里不多提
},
"presentation": {
"echo": true,
"reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never。具体参见VSC的文档
"focus": false, // 设为true后可以使执行task时焦点聚集在终端,但对编译c和c++来说,设为true没有意义
"panel": "shared" // 不同的文件的编译信息共享一个终端面板
},
"problemMatcher":"$gcc" // 如果你不使用clang,去掉前面的注释符,并在上一条之后加个逗号。照着我的教程做的不需要改(也可以把这行删去)
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "8.1",
"compilerPath": "C:\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}