最完美的vscode配置文件(C/C++)
效果演示
如图所示,可以在vscode工具栏中方便切换C/C++编译器以及单文件/多文件编译。
使用MinGW-win64编译器编译C/C++文件,可切换内/外部终端运行程序,并自动暂停。
launch.josn配置
{
"version": "0.2.0",
"configurations": [
//使用外部终端
{
"name": "Debug-c-single",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"args": [
"/c",
"${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe", //(单文件调试)
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "build_single"
},
{
"name": "Debug-c-multiple",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"args": [
"/c",
"${workspaceFolder}\\${workspaceRootFolderName}.exe", //(多文件调试)
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "build_multiple"
},
{
"name": "Debug-cpp-single",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"args": [
"/c",
"${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe", //(单文件调试)
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "build_cpp_single"
},
{
"name": "Debug-cpp-multiple",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"args": [
"/c",
"${workspaceFolder}\\${workspaceRootFolderName}.exe", //(多文件调试)
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "build_cpp_multiple"
},
//使用内部终端
// { //‘调试(Debug)
// "name": "Debug-c-single",
// "type": "cppdbg",
// "request": "launch",
// "program": "${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe", //(单文件调试)
// "args": [],
// "stopAtEntry": false, // 这里改为true作用等同于在main处打断点
// "cwd": "${fileDirname}", // 调试程序时的工作目录,即为源代码所在目录,不用改
// "environment": [],
// "externalConsole": false, // 改为true时为使用cmd终端,推荐使用vscode内部终端
// "internalConsoleOptions": "neverOpen", // 设为true为调试时聚焦调试控制台,新手用不到
// "MIMode": "gdb",
// "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
// "preLaunchTask": "build_single" // 调试开始前执行的任务(任务依赖),与tasks.json的label相对应
// },
// { //‘调试(Debug)
// "name": "Debug-c-multiple",
// "type": "cppdbg",
// "request": "launch",
// "program": "${workspaceFolder}\\${workspaceRootFolderName}.exe", //(多文件调试)
// "args": [],
// "stopAtEntry": false, // 这里改为true作用等同于在main处打断点
// "cwd": "${fileDirname}", // 调试程序时的工作目录,即为源代码所在目录,不用改
// "environment": [],
// "externalConsole": false, // 改为true时为使用cmd终端,推荐使用vscode内部终端
// "internalConsoleOptions": "neverOpen", // 设为true为调试时聚焦调试控制台,新手用不到
// "MIMode": "gdb",
// "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
// "preLaunchTask": "build_multiple" // 调试开始前执行的任务(任务依赖),与tasks.json的label相对应
// },
// { //‘调试(Debug)
// "name": "Debug-cpp-single",
// "type": "cppdbg",
// "request": "launch",
// "program": "${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe", //(单文件调试)
// "args": [],
// "stopAtEntry": false, // 这里改为true作用等同于在main处打断点
// "cwd": "${fileDirname}", // 调试程序时的工作目录,即为源代码所在目录,不用改
// "environment": [],
// "externalConsole": false, // 改为true时为使用cmd终端,推荐使用vscode内部终端
// "internalConsoleOptions": "neverOpen", // 设为true为调试时聚焦调试控制台,新手用不到
// "MIMode": "gdb",
// "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
// "preLaunchTask": "build_cpp_single" // 调试开始前执行的任务(任务依赖),与tasks.json的label相对应
// },
// { //‘调试(Debug)
// "name": "Debug-cpp-multiple",
// "type": "cppdbg",
// "request": "launch",
// "program": "${workspaceFolder}\\${workspaceRootFolderName}.exe", //(多文件调试)
// "args": [],
// "stopAtEntry": false, // 这里改为true作用等同于在main处打断点
// "cwd": "${fileDirname}", // 调试程序时的工作目录,即为源代码所在目录,不用改
// "environment": [],
// "externalConsole": false, // 改为true时为使用cmd终端,推荐使用vscode内部终端
// "internalConsoleOptions": "neverOpen", // 设为true为调试时聚焦调试控制台,新手用不到
// "MIMode": "gdb",
// "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
// "preLaunchTask": "build_cpp_multiple" // 调试开始前执行的任务(任务依赖),与tasks.json的label相对应
// },
]
}
tasks.josn配置
{
"version": "2.0.0",
"tasks": [
{
"label": "build_single",
"type": "shell",
"command": "gcc",
"args": [
"${file}", //(单文件编译)
"-o",
"${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe", //(单文件编译)
"-g",
"-Wall",
"-static-libgcc",
"-fexec-charset=GBK",
"-std=c11", //选择C标准
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"problemMatcher": "$gcc"
},
{
"label": "build_cpp_single",
"type": "shell",
"command": "g++",
"args": [
"${file}", //(单文件编译)
"-o",
"${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe", //(单文件编译)
"-g",
"-Wall",
"-static-libgcc",
"-fexec-charset=GBK",
"-std=gnu++14", //选择C标准
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"problemMatcher": "$gcc"
},
{
"label": "build_multiple",
"type": "shell",
"command": "gcc",
"args": [
"${workspaceFolder}\\*.c", //(多文件编译)
"-o",
"${workspaceFolder}\\${workspaceRootFolderName}.exe", //(多文件编译)
"-g",
"-Wall",
"-static-libgcc",
"-fexec-charset=GBK",
"-std=c11", //选择C标准
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"problemMatcher": "$gcc"
},
{
"label": "build_cpp_multiple",
"type": "shell",
"command": "g++",
"args": [
"${workspaceFolder}\\*.cpp",//(多文件编译)
"-o",
"${workspaceFolder}\\${workspaceRootFolderName}.exe", //(多文件编译)
"-g",
"-Wall",
"-static-libgcc",
"-fexec-charset=GBK",
"-std=gnu++14", //选择C标准
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"problemMatcher": "$gcc"
},
{
"label": "run",
"type": "shell",
"dependsOn": "build_single",
"command": "${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe", //(单文件编译)
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new"
}
},
{
"label": "run",
"type": "shell",
"dependsOn": "build_cpp_single",
"command": "${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe", //(单文件编译)
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new"
}
},
{
"label": "run",
"type": "shell",
"dependsOn": "build_multiple",
"command": "${workspaceFolder}\\${workspaceRootFolderName}.exe", //(多文件编译)
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new"
}
},
{
"label": "run",
"type": "shell",
"dependsOn": "build_cpp_multiple",
"command": "${workspaceFolder}\\${workspaceRootFolderName}.exe", //(多文件编译)
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new"
}
},
]
}
本文完。
以上配置文件由SHIKE原创,未经允许研究转载!
来自陕西