在安装vscode之前要确保自己已经配置了MinGW
教程:手把手教程:MinGW在windows下的配置-CSDN博客
官网下载VScode:
Visual Studio Code - Code Editing. Redefined
环境配置:
注意VScode文件命名以及路径不能出现中文等字样!!!且换路径的时候在windows下是两个//不然要报错。
安装包:
创建文件:
文件目录如下:
c_cpp_properties.json内容:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "D:\\Software\\mingw64\\bin\\g++.exe", /*bin目录下的g++.exe,两个反斜杠\\*/
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
替换compilePath的路径:
launch.json文件内容:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\build\\${fileBasenameNoExtension}.exe", /*收纳exe可执行文件*/
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Software\\mingw64\\bin\\gdb.exe", /*bin目录下的gdb.exe,两个反斜杠\\*/
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++"
}
]
}
修改miDebuggerPath的路径:
tasks.json
内容如下:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++",
"command": "D:\\Software\\mingw64\\bin\\g++.exe", /*bin目录下的g++.exe,两个反斜杠\\*/
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\build\\${fileBasenameNoExtension}.exe", /*收纳exe可执行文件*/
"-fexec-charset=GBK", /*中文乱码*/
"-I",
"F:\\C++", /*c/c++项目的文件夹,两个反斜杠\\*/
"-std=c++17"
],
"options": {
"cwd": "D:\\Software\\mingw64\\bin" /*bin目录,两个反斜杠\\*/
},
"problemMatcher": [
"$gcc"
],
"group": "build",
}
]
}
修改一下三个地方:最后在调试的时候需要把生产的.exe文件放到build文件下,且未弹出来窗口时需要加入以下指令:
system("pause");