VS2015玩崩了,电脑内存也不够装其它版本了,干脆直接换个轻量级的
在网上看的各种大神的帖子,也走了些弯路,总结一下自备自用
本文主要包含:VSCode安装、C++编译环境搭建、使用VSCode调试C++程序

1.VSCode安装

官网下载:https://code.visualstudio.com/

vs code vite 调试typescript_g++


安装过程一路下一步即可

安装插件

搜C/C++、Chinese、Code即可找到

主要就这三个

vs code vite 调试typescript_json_02

2.C++编译环境搭建

win+r 输cmd

输入g++ -v如果啥也没有那么你就需要先安装mingw-w64配置编译环境

离线版下载地址:https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z/download

我记得网速贼慢14M的压缩包解压出来是50M的.7z文件(你可能还需要一个.7z的解压软件)再解压就是553M的我们要的文件,这个文件压缩率真牛!

我也上传了一份下载好的离线文件,需要的可取

没有积分的可以私我邮箱发你

解压出来的文件可以直接用了,给放在你自己喜欢的安装路径下,要设置一下环境变量

此电脑→属性→高级系统设置→环境变量→系统变量那一栏找到path双击→新建 把你文件夹中bin文件夹的绝对地址写进来如图

然后要点确定,确定,确定三个哦,我就没点完×了过

vs code vite 调试typescript_c++_03


再打开命令行窗口,

win+r 输cmd

输入g++ -v

出来类似结果即可,编译环境OK

vs code vite 调试typescript_g++_04


3.调试

调试要自己配置一些文件才行

例子:

新建 start.cpp,简单代码如下

#include"iostream"
using namespace std;
int main()
{
cout<<"start up!"<<endl;
int a[]={0,1,2,3,4,5,6,7,8,9};
for (int i = 0; i < 10; i++)
    {
        a[i]++;
        cout<<a[i]<<endl;
    }
}

右键,然后点击Run Code即可运行代码,文件夹下生成了个start.exe文件

vs code vite 调试typescript_json_05


点击甲壳虫会生成一个.vscode文件夹

里面需要配置 launch,json tasks.json 这两个文件

launch.json内容如下:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
           
            "program":"${workspaceFolder}/start.exe", //给start.exe换成要调试的exe文件
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build on WSL",
           
        }
    ]
}

tasks.json 文件内容如下:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build on WSL",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}/start.exe",//换成调试的exe文件
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

只用给要调试的文件换掉就行了,每次调试的时候都要设置成对应的文件

页面切换会cpp文件,打断点,点击下图箭头或者F5开始调试

vs code vite 调试typescript_c++_06


vs code vite 调试typescript_g++_07

搞定