第一步,官网下载VSCode
1.官网下载好
我全部勾选了
2.下载这些扩展
第一个,第四个是必需的
第二步,MinGW-w64官网下载gcc的资源
1.下载64位的
2.下载好之后解压到设置的特定文件中
3.配置环境变量,点击Path
添加这行环境,路径是你下载配置环境的路径
配置完毕,一路点击确定
3.测试是否安装成功
win+R:cmd出现这行代码就是成功安装
第三步,创建文件
选择通过code打开即可
第四步,编写如下代码还是有报错
修正:
1.创建.vscode文件夹,并设置三个.josn的子文件(c_cpp_properties.json和launch.json和launch.json )
(1)c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "gcc-x64",
"compilerPath": "D:/Environments/mingw64/bin/g++.exe" /*放着你的第二步下载好的mingw64文件下的g++.exe路径*/
}
],
"version": 4
}
(2)launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/Environments/mingw64/bin/gdb.exe", //放置自己的路径
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
(3)tasks.json
{
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "D:/Environments/mingw64/bin"
},
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:/Environments/mingw64/bin/g++.exe", //放置自己的路径
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:/Environments/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
第五步,创建一个.c文件,直接编译运行输出Hello,world!
#include <stdio.h>
int main()
{
// printf() 中字符串需要引号
printf("Hello, World!");
return 0;
}
运行结果: