一、tasks.json文件
{
"tasks": [
{
"type": "shell",//任务执行的是shell命令,若用bulit在此配置报错,可能是exe路径原因
"label": "C/C++: g++.exe build active file",
"command": "E:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-include",
"${workspaceRoot}\\.vscode\\head.h",//编译时包含head文件
"-o",
"E:\\learnc++\\exe\\${fileBasenameNoExtension}.exe"//创建一个存放exe的文件夹
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
// 任务分组,因为是tasks而不是task,意味着可以连着执行很多任务
// 在build组的任务们,可以通过在Command Palette(F1) 输入run build task来运行
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
head.h-维持运行终端显示,结合tasks.json中的${workspaceRoot}\\.vscode\\head.h字段设置。放到.vscode文件夹即可(可选)
#include <stdlib.h>
static void before(void) __attribute__((constructor));
static void after(void) __attribute__((destructor));
static void middle(void);
static void before()
{
system("chcp 65001"); //切换字符集
system("cls");
}
static void after()
{
system("echo.");
system("pause");
}
二、launch.json文件
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "E:\\learnc++\\exe\\${fileBasenameNoExtension}.exe",\\注意自己的路径
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,\\运行结果以外面终端显示
"MIMode": "gdb",
"miDebuggerPath": "E:\\MinGW\\bin\\gdb.exe",\\注意自己的路径
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
?
|