VSCode 配置不让 C++ 程序运行一闪而过

Visual Studio Code(简称 VSCode)是由微软开发的一个轻量且强大的代码编辑器。

最近在学 C++,调试需要配置 launch.json,所以参阅相关文档配置后,发现每次调试启动 exe 都会单独打开一个窗口,每个 .cpp 文件里都要加上 system("pause"); 才能保证窗口不会一闪而过。所以… 如果能在 VSCode 自带的 Terminal 里面运行 exe 岂不是美滋滋?但似乎 VSCode 目前不支持…

参见:#634 #16890 #35 #8222

并不完美的解决方法

通过配置 launch.json 的 programC://Windows/System32/cmd.exe,然后 args 加上参数。但是这样断点不能用了…

launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "C://Windows/System32/cmd.exe",
"args": ["/c", "${workspaceRoot}/build/${fileBasenameNoExtension}.exe", "&", "echo.", "&", "pause"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}

tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "g++",
"args": [
"-g", "${file}", "-o", "build/${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}/build"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}

还有一个方法

Workaround: Add this snippet to your launch.json and the internal terminal of VS Code will be used instead 😂

1
2
3
4
5
6
7
8
"pipeTransport": {
"pipeCwd": "/usr/bin",
"pipeProgram": "/bin/sh",
"debuggerPath": "/usr/bin/gdb",
"pipeArgs": [
"-c"
]
},

LINK

P.S. 如果找到了其他方法还会继续更新的…

本站文章除注明转载外均为原创,未经允许不要转载哇. ヾ(゚ー゚ヾ) http://qwqaq.com/4cd79212.html
分享到 评论