本人沒使用系統cmd視窗,而是使用了vscode內建終端,目的是為了之後輸出中文的時候不亂碼(vscode是utf-8,cmd是gbk,乾脆全部使用vscode,不使用系統cmd作為輸出視窗)
附上配置檔案:
launch.json
{
// 使用 IntelliSense 瞭解相關屬性。
// 懸停以檢視現有屬性的描述。
// 欲瞭解更多資訊,請訪問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和除錯活動檔案",
"type": "cppdbg",
"request": "launch",
// "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
// "args": [],
"program": "C:\\Windows\\System32\\cmd.exe",
"args": ["/c","${fileDirname}\\${fileBasenameNoExtension}.exe","&","pause"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false, // 修改此項為true,執行時可以彈出console終端,此處不使用系統終端,故為false
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "為 gdb 啟用整齊列印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活動檔案"
}
]
}
task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活動檔案",
"command": "C:\\Program Files\\mingw64\\bin\\g++.exe",
"args": [
// "-fexec-charset=GBK", //這裡沒用到系統終端,故不改成gbk格式
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "偵錯程式生成的任務。"
}
],
"version": "2.0.0"
}