vscode配置C++开发环境(纯纯小白版)

目录

  1. 下载vscode
  2. 安装相关拓展插件
  3. 下载编辑器
  4. 环境配置
  5. 配置.vscode文件
  6. 新建调试

1.下载vscode

  • 对应自己电脑的版本去下载即可,挺方便的
    -官方下载地址:https://code.visualstudio.com/#alt-downloads

  • vscode设置中文环境教程

    http://www.chuancn.cn/post/将VSCode设置成中文语言环境在这里插入图片描述

2、安装相关拓展插件

  • 在拓展商店里搜索安装C/C++插件
  • 安装完之后记得重启

在这里插入图片描述

3.下载编辑器

  • 下载MinGW-W64 GCC-8.1.0编译器
    官网下载地址
    具体可按自己需要情况而定,一般推荐下载压缩包,速度快(×86_64-posix-sjlj)
    在这里插入图片描述

  • 下载到自己相应的文件路径下,我一般下载在x86文件夹下,然后将压缩包解压到当前目录下

在这里插入图片描述

  • 打开文件夹里的bin目录,并复制该bin路径留作配置环境变量用

4.配置path变量

  • 搜索此电脑,找到并打开属性
    在这里插入图片描述
  • 点击高级系统设置
    在这里插入图片描述
  • 点击环境变量

在这里插入图片描述

  • 找到path并编辑 和新建
  • 把下载的MinGW里的bin目录路径粘贴在这里
    在这里插入图片描述
    在这里插入图片描述
  • 检查有没有配置成功
    输入g++ -v
    在这里插入图片描述
    出现上述图片说明配置成功

5.配置.vscode文件

  • 首先新建文件夹(文件夹名字一定要是英文的,要不然后面编译出问题)
  • 在该文件夹下创建一个.vscode文件夹工作空间,并创建三个文件,分别是c_cpp_properties.json,launch.json,tasks.json(记得ctr+f去替换成自己的bin路径)
  • c_cpp_properties.json
{
    "configurations": [
        {
          "name": "Win64",
          "includePath": [
              "${workspaceFolder}/**",
              "C:/Program Files (x86)/C++环境/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.4.0/include",
              "C:/Program Files (x86)/C++环境/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.4.0/include-fixed",
              "C:/Program Files (x86)/C++环境/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.4.0/../../../../x86_64-w64-mingw32/include",
              "C:/Program Files (x86)/C++环境/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/c++",
              "C:/Program Files (x86)/C++环境/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32",
              "C:/Program Files (x86)/C++环境/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/c++/backward"
            ],
          "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
          "windowsSdkVersion": "10.0.17763.0",
          "compilerPath": "C:\\Program Files (x86)\\C++环境\\mingw64\\bin\\g++.exe",   
          "cStandard": "c11",
          "cppStandard": "c++17",
          "intelliSenseMode": "${default}"
        }
      ],
      "version": 4
}

includepath里的内容从(g++ -v -E -x c++ -)命令打开的cmd里复制过去
在这里插入图片描述

  • launch.json
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files (x86)\\C++环境\\mingw64\\bin\\gdb.exe",	
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "task g++"
        }
    ]
}

  • tasks.json
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
        "type": "shell",
        "label": "task g++",
        "command": "C:\\Program Files (x86)\\C++环境\\mingw64\\bin\\g++.exe",	
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "-I",
            "C:\\Users\\86198\\Desktop\\力扣刷题冲冲冲\\vsCode",    
            "-std=c++17"
        ],
        "options": {
            "cwd": "C:\\Program Files (x86)\\C++环境\\mingw64\\bin"
        },
        "problemMatcher":[
            "$gcc"
        ],
        "group": "build",
        
        }
    ]
}


6. 新建调试

  • 在新建的文件夹下新建一个cpp文件(注意一定要是英文名,不可以出现中文会报错的!)

#include <stdio.h>
#include <windows.h>
int main()
{
    printf("Hello World\n");
    system("pause");
    return 0;
}

  • 调试运行 成功!!
    在这里插入图片描述

最后

  • 新建的文件夹路径一定要是全英文
  • 文件夹下新建的cpp一定也要是全英文
  • 如果include报错就是includepath少东西
  • 有什么遗漏的可以去官方文档里查找一下
  • 接下来就可以开启我们的c++开发之旅啦!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值