1.安装MinGW编译器,配置MinGW环境
https://blog.youkuaiyun.com/mantou_riji/article/details/123593123
2.安装C/C++扩展
3.配置编译器路径,-c_cpp_properties.json文件
ctrl+shift+P, 输入C/C++
- 配置编译器路径
- 修改IntelliSense模式为windows-gcc-x64
- 出现c_cpp_properties.json文件
作用:c_cpp_properties.json 主要用来设置包含 头文件的路径 ,设置 C/C++ 支持的 版本号 等
内容:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Program Files\\CodeBlocks\\MinGW\\bin\\gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
4.tasks.json文件
tasks.json:告诉VSCode代码如何编译代码
终端->配置任务->使用模板创建tasks.json文件 可以打开tasks.json。
内容:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true",
"/t:build",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
4.launch.json文件
launch.json 是用于运行和调试的配置文件
运行->启动调试->c++(GDB/LLDB)->默认配置
可以打开launch.json文件。
内容
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cpp.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\CodeBlocks\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: cpp.exe 生成活动文件"
}
]
}
可以进行修改方便调试使用。