配置文件
在.vscode文件夹下创建三个文件:c_cpp_properties.json 、launch.json 、``
c_cpp_properties.json文件配置
- 复制下面的配置信息
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"c:/mingw/include/**",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include/c++",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include/c++/mingw32",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include/c++/backward",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../include",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include-fixed"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"path": [
"${workspaceRoot}",
"c:/mingw/include/**",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include/c++",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include/c++/mingw32",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include/c++/backward",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../include",
"c:/mingw/bin/../lib/gcc/mingw32/8.2.0/include-fixed"
]
}
}
],
"version": 4
}
- 打开cmd,搜索
gcc -v -E -x c++ -
- 修改 “includePath” 和 “Path”,将图示这几行代替其中路径即可
launch.json文件配置
根据自己路径修改 "miDebuggerPath"
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/MinGW/bin/gdb.exe",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json文件配置
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}/exe/${fileBasenameNoExtension}.exe"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"\\"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
修改配置参数
解决VSCode调试C/CPP,CMD闪退
上述代码以及修改过了:"program": "C:\\Windows\\System32\\cmd.exe",
将程序运行在外部控制台【推荐】
打开.vscode 文件夹下的 launch.json 文件,找到 "externalConsole": false , 将 false 改为true 并保存。
收纳生成的 exe 可执行文件
- 打开.vscode 文件夹下的 task.json 文件,找到
"${fileDirname}\\${fileBasenameNoExtension}.exe" - 修改成
"${fileDirname}\\bin\\${fileBasenameNoExtension}.exe" 并保存,同理,launch.json 下也有相同的字段,需要你修改 - 在源文件同目录下新建 bin文件夹,程序运行后,可执行文件将会生成在里面(其中 bin 可修改成你喜欢的英文名字)
|