天天看點

vscode配置非常重要的一點是,設定好配置檔案之後,要把vscode重新開機,不然會有bug

task.json用于g++編譯和事後處理

{
	"version": "2.0.0",
	"tasks": [
		{//生成編譯檔案任務
			"type": "shell",
			"label": "C/C++: g++.exe build active file",
			"command": "C:\\MinGW\\bin\\g++.exe",
			"args": [
				"-g",
				"${file}",
				"-o",
				"${fileDirname}\\${fileBasenameNoExtension}.exe",//生成檔案的位址
			],
			"options": {
				"cwd": "${workspaceFolder}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": "build"
		},
		{ //删除二進制檔案任務
			            "type": "shell",
			            "label": "delete output file",
			            "command": "del",
			            "args": [
			                "${fileDirname}\\${fileBasenameNoExtension}.exe"
			            ],
			            "presentation": {
			                "reveal": "silent", //删除過程不切換終端(專注程式輸出)
			            }
			        }
	]
}
           

launch.json用于GDB調試

{
    "version": "0.2.0",
    "configurations": [

   {//進行gdb的過程
            "name": "g++.exe - 生成和調試活動檔案",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "為 gdb 啟用整齊列印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file",//程序gdb之前的工作:生成.exe檔案
            "postDebugTask": "delete output file" //gdb之後的工作,将二進制檔案删除
        }
    ]
}
           

非常重要的一點是,設定好配置檔案之後,要把vscode重新開機,不然會有bug

繼續閱讀