Many friends in the use of VS Code, after running the program window console may flash past. At this point, the code is completely running, but the result is not visible. To do this, we can do configution by setting up a CMD configuration, as shown below:
Open the launch.json file and add
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"args": [
"/C",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole":true
},
Note that the code is added in
"version": "0.2.0",
"configurations": [
and
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
In this case, you may find that this is just a case of keeping the old configuration and building a new platform, so that the runtime starts with window… Just run it
For convenience, share launch.json as follows:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"args": [
"/C",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole":true
},
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
Hope the above content is helpful to readers (especially students)!
In the latest update, the Windows command box method is not debugable, so the breakpoint pause method is still recommended. hhhh
Read More:
- How to solve the problem that the console window disappears in a flash after visual studio 2017 runs
- Solution to the flash of visual studio console program output window
- Flashback problem of output window of visual studio 2017 console program
- Problem solving – vs debugging window flash solution
- The problem of C + + compile result window flash by
- The problem of running result window flash of vs2015
- Solution to the problem of console flash in vs2017 runtime
- Solve the problem of error running console reported by pycharm Python console
- The problem of window flash after C + + program is compiled and run
- The problem of flash back by pressing enter window when debugging or executing program in Visual Studio C
- Solution to the problem of console output window’s CMD flashing back when vs2015 writes C + + program
- Solve the problem of Tomcat console and HTML garbled
- VS2010 debugging window flash solution
- Solve the problem of flash back in VS2010
- Vscode debug Java console input: evaluation failed because the thread is not suspended
- Solve the problem of visual studio console flashback
- Solve the problem that data cannot be input in idea console
- Visual studio console program output window flashed by
- The solution of console flash in C + +
- Solve the flash card problem of winfrom project form