在网上找了一些安装的教程,到最后都运行失败了。不过也没白找,最起码知道需要安装插件和编译器了。
MinGW官网进行下载安装。https://sourceforge.net/projects/mingw/files/
我下载的是压缩包,解压就可以使用了。
然后点击左上角的install – Apply Changes 安装
官网下载安装即可 https://code.visualstudio.com/
使用VSCode打开一个文件夹(路径不包含中文)。新建一个hello.c文件。
写一段hello world。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gdb_Launcher",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\VScode\\mingw64\\bin\\gdb.exe",//修改成你自己的gdbl路径
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc.exe build active file"
}
]
}
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "D:\\VScode\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\VScode\\mingw64\\bin"
}
},
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "D:\\VScode\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\VScode\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
]
}
],
"version": "2.0.0"
gcc test.c -o test.exe
将test.c编译成.exe文件
./test.exe
运行.exe文件
大功告成。
setting - encode - gb2312
如果还是乱码的话,请新建一个文件。因为之前乱码的文件编码不是gb2312。