Regarding the problem of window flashback, you can add it to the program:
#include <stdlib.h>
system("pause");
Of course, you can also make some modifications in the configuration file in the .vscode file to solve this problem:
Modify under "configurations" in launch.json:
"program": "C:\\Windows\\System32\\cmd.exe",
"args": ["/c","${fileDirname}\\${fileBasenameNoExtension}.exe","&","pause"],
You can directly assign the following and paste it into your launch.json:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "C:\\Windows\\System32\\cmd.exe",
"args": ["/c","${fileDirname}\\${fileBasenameNoExtension}.exe","&","pause"],
// "program":"${fileDirname}\\${fileBasenameNoExtension}.exe",
// "args":[],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe 生成活动文件"
}
]
}
The part involving the path above should be changed to your own path. The "true" in line 19 above means that you are using an external terminal. If you want to use the internal terminal of vscode, just change "false".
Regarding Chinese garbled characters, tasks.json needs to be modified
Add: "-fexec-charset=GBK"
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "C:\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-fexec-charset=GBK"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
If VSCode is not installed yet, the download and installation of VSCode is also very simple: Visual Studio Code - Code Editing. Redefined
In addition, MinGW needs to be downloaded:
MinGW - Minimalist GNU for Windows download | SourceForge.net
MinGW official website: MinGW-w64
On the official website, click "Downloads"-->" SourceForge "