当前位置:   article > 正文

2024最新Win系统下VSCode下载安装与配置C/C++教程_安装配置vscode c++

安装配置vscode c++

2024最新Win系统下VSCode下载安装与配置C/C++教程

1、下载安装VSCode

官网地址

https://code.visualstudio.com/
  • 1

赋值粘贴进入后,选择windows系统进行下载

image-20240325134915117

下载完毕后,点击exe文件开始进入安装环节

image-20240325140213014

image-20240326085837033

image-20240326085944316

2、安装运行时环境GC++

进入官网

https://nuwen.net/mingw.html
  • 1

image-20240325144027850

下载后双击运行开始安装

image-20240325144531599

image-20240326090338735

GC++的环境配置

上一步安装之后,进入到安装目录,进入bin文件夹,然后拷贝当前路径

image-20240326091413054

进入系统环境变量的配置页面,可以按下win键->点击搜索框->输入环境->,或者进入设置->系统->系统信息->高级系统设置

image-20240326091723342

image-20240326091909021

上述两种方法均可以进入当前界面,配置完毕后点击三次确定,进入下一步

image-20240326092753416

键盘按下win+R,输入cmd,点击回车,进入dos命令窗口,输入 g++ --version(++和–中间有一个空格),检验是否配置成功,如果显示当前版本号,就可以进入下一步了

image-20240326093615923

image-20240326093620522

3、安装VSCode插件

打开安装好的VSCode,安装C/C++插件

image-20240326100918059

image-20240326101329469

如果有需要汉化的,(不建议,新手也不建议,要敢于尝试,实在不行的选择是可以汉化),插件如下所示,点击install即可

image-20240326101512325

4、配置程序调试环境
4.1确定文件存储路径

这里需要我们确定后续的程序文件存储路径,可以理解为是后续所有C/C++代码的工程根目录,即即将做的环境配置仅在此目录下生效!!!我的以下图为例。

image-20240326112118455

然后在VSCode里面打开上述文件夹,点击File->Open Folder

image-20240326112239968

image-20240326112356767

然后刚开始就长这样

image-20240326112526471

4.2新建文件夹【.vscode】

此处的文件夹必须为【】括起来的这个名字

image-20240326112819294

4.3在.vscode文件夹里新建四个配置文件
1、c_cpp_properties.json
2、launch.json
3、settings.json
4、tasks.json
  • 1
  • 2
  • 3
  • 4

image-20240326113047813

填写对应的文件信息

c_cpp_properties.json
{
  "configurations": [
    {
      "name": "Win64",
      "includePath": ["${workspaceFolder}/**"],
      "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
      "windowsSdkVersion": "10.0.18362.0",
      "compilerPath": "C:/MinGW/bin/g++.exe",
      "cStandard": "c17",
      "cppStandard": "c++17",
      "intelliSenseMode": "gcc-x64"
    }
  ],
  "version": 4
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
launch.json
{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "(gdb) Launch", 
        "type": "cppdbg", 
        "request": "launch", 
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", 
        "args": [], 
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "externalConsole": true, 
        "MIMode": "gdb",
        //这里仍然是要进行修改为自己安装的目录
        "miDebuggerPath": "D:/Users/jinHuan/Downloads/MinGW/bin/gdb.exe",
        "preLaunchTask": "g++",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ]
      }
    ]
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
settings.json
{
    "files.associations": {
      "*.py": "python",
      "iostream": "cpp",
      "*.tcc": "cpp",
      "string": "cpp",
      "unordered_map": "cpp",
      "vector": "cpp",
      "ostream": "cpp",
      "new": "cpp",
      "typeinfo": "cpp",
      "deque": "cpp",
      "initializer_list": "cpp",
      "iosfwd": "cpp",
      "fstream": "cpp",
      "sstream": "cpp",
      "map": "c",
      "stdio.h": "c",
      "algorithm": "cpp",
      "atomic": "cpp",
      "bit": "cpp",
      "cctype": "cpp",
      "clocale": "cpp",
      "cmath": "cpp",
      "compare": "cpp",
      "concepts": "cpp",
      "cstddef": "cpp",
      "cstdint": "cpp",
      "cstdio": "cpp",
      "cstdlib": "cpp",
      "cstring": "cpp",
      "ctime": "cpp",
      "cwchar": "cpp",
      "exception": "cpp",
      "ios": "cpp",
      "istream": "cpp",
      "iterator": "cpp",
      "limits": "cpp",
      "memory": "cpp",
      "random": "cpp",
      "set": "cpp",
      "stack": "cpp",
      "stdexcept": "cpp",
      "streambuf": "cpp",
      "system_error": "cpp",
      "tuple": "cpp",
      "type_traits": "cpp",
      "utility": "cpp",
      "xfacet": "cpp",
      "xiosbase": "cpp",
      "xlocale": "cpp",
      "xlocinfo": "cpp",
      "xlocnum": "cpp",
      "xmemory": "cpp",
      "xstddef": "cpp",
      "xstring": "cpp",
      "xtr1common": "cpp",
      "xtree": "cpp",
      "xutility": "cpp",
      "stdlib.h": "c",
      "string.h": "c"
    },
    "editor.suggest.snippetsPreventQuickSuggestions": false,
    "aiXcoder.showTrayIcon": true
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
tasks.json
{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "g++",
        "command": "g++",
        "args": [
          "-g",
          "${file}",
          "-o",
          "${fileDirname}/${fileBasenameNoExtension}.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
          }
        },
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

分别把对应的文件拷贝修改后,切记保存Ctrl + S,后续的C/C++代码就都需要在含.vscode文件夹的【同级目录】内!!!我这新建两个同级目录C和C++,用于接下来的调试

image-20240326114451490

5、编写测试案例
#include <iostream>
using namespace std;
int main(){
    int a = 100,b = 10;
    cout << a + b <<endl;
    cout << "hello" << endl;
    cout << "hello" << endl;
    cout << "hello" << endl;
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
运行程序

image-20240326153109838

image-20240326153132196

调试程序

image-20240326153602784

image-20240326153715479

解决乱码问题

点击左下角小齿轮,进入Settings,输入encoding,将编码格式修改为GBK

image-20240326154029332

再次进入调试模式,乱码问题解决

image-20240326154149355

至此结束,回顾强调本文重点:

1、安装路径坚决不能有中文
2、配置GC++环境变量的时候,一定记得不要写错
3、配置文件夹名字是 .vscode 千万别忘记.
4、配置文件有两个要修改路径的,
	一定记清楚 分隔符 要不就是 \\ 要不就是/
	不是\
5、新建不同的项目文件夹的时候,注意是和配置文件夹.vscode同级别
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

好了,收工,遇到什么问题,欢迎私信,看到就回

开始很容易,坚持很牛皮,加油

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/615153
推荐阅读
相关标签
  

闽ICP备14008679号