解決方案是用cmd運行編譯生成的exe文件
將launch.json改為
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch (GDB)",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x86",
"program": "${file}.exe",
"miDebuggerPath": "D:\\MinGW64\\bin\\gdb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"externalConsole": true,
"preLaunchTask": "g++",
//---------------------------------------------
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"args": ["/C", "${file}.exe", "&", "pause"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true
}
]
}
實測是可行的,但是打斷點調試受到了影響(雖然我大多數都是輸出中間值調試)。