下载VSCode

https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-user

下载mingw64

图片说明

认识我的可以在QQ群里下载到,不认识我的自己去网上下也行,就是有点慢。

移动并重命名

图片说明

放到C盘根目录下,并且重命名为MinGW,因为后面的文件的引用位置也要调用这个位置,如果你不打算调的话就和我一样做。

配置环境变量

回到“此电脑”

图片说明

右击空白区域后左击属性

图片说明

依次点击高级系统设置、环境变量

图片说明

双击这个反选区域,然后点新建

图片说明

把这句话C:\MinGW\bin粘贴进去

创建代码文件夹

随便在一个位置创建一个代码文件夹(英文路径),然后再该文件夹下创建.vscode文件夹

然后在.vscode文件夹下,手动创建如下.json文件。

c_cpp_properties.json

内容如下,粘贴即可,下同

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\MinGW\\bin\\gcc.exe",
            "browse": {
                "path": [
                    "${workspaceFolder}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch (GDB)", // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg", // 配置类型,这里只能为cppdbg
            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
            "targetArchitecture": "x64", // 生成目标架构,一般为x86或x64,可以为x86, arm, arm64, mips, x64, amd64, x86_64
            "program": "${file}.exe", // 将要进行调试的程序的路径
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
            "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
            "cwd": "${workspaceRoot}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
            "environment": [],
            "MImode": "gdb",
            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
            "preLaunchTask": "g++" // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
        }
    ]
}

settings.json

{
    "C_Cpp.intelliSenseEngineFallback": "Disabled",
    "C_Cpp.clang_format_style": "{BasedOnStyle: Google, IndentWidth: 4}",
    "C_Cpp.clang_format_fallbackStyle": "{BasedOnStyle: Google, IndentWidth: 4}",
    "files.associations": {
        "cmath": "cpp",
        "iostream": "cpp",
        "new": "cpp",
        "*.tcc": "cpp",
        "ostream": "cpp",
        "sstream": "cpp",
        "array": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cstring": "cpp",
        "ctime": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "fstream": "cpp",
        "functional": "cpp",
        "initializer_list": "cpp",
        "iomanip": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "system_error": "cpp",
        "type_traits": "cpp",
        "tuple": "cpp",
        "typeinfo": "cpp",
        "utility": "cpp",
        "atomic": "cpp",
        "bitset": "cpp",
        "cfenv": "cpp",
        "chrono": "cpp",
        "cinttypes": "cpp",
        "codecvt": "cpp",
        "complex": "cpp",
        "condition_variable": "cpp",
        "csetjmp": "cpp",
        "csignal": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cuchar": "cpp",
        "forward_list": "cpp",
        "list": "cpp",
        "unordered_set": "cpp",
        "future": "cpp",
        "memory": "cpp",
        "mutex": "cpp",
        "numeric": "cpp",
        "ratio": "cpp",
        "scoped_allocator": "cpp",
        "shared_mutex": "cpp",
        "thread": "cpp",
        "typeindex": "cpp",
        "valarray": "cpp",
        "map": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "string_view": "cpp"
    },
    "terminal.explorerKind": "external",
    "C_Cpp.errorSquiggles": "Enabled",
    "python.linting.flake8Enabled": false,
    "python.formatting.provider": "yapf",
    "python.linting.flake8Args": [
        "--max-line-length=248"
    ],
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true
}

tasks.json

{
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${file}.exe",
    ], // 编译命令参数
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "${workspaceRoot}"
        ],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

vscode打开这个代码文件夹

图片说明

他让安装什么就安装什么

图片说明

再去安装一个code runner

图片说明

这样就可以了。

图片说明

最后的微调

点左下角调一下设置,顶端搜索run in terminal然后勾选

图片说明

最后搜索C_Cpp: Clang_format_fallback StyleC_Cpp: Clang_format_style,改成{BasedOnStyle: Google, IndentWidth: 4}

图片说明

你可以在这个文件下编辑、调试、编译C/C++代码了。