win10 下用 vs code 编译调试代码的过程 (MinGW)

一、下载软件

官网下载 vs code 和 MinGW。

二、建立工作区

1、建立文件夹 “ProjectTest”,其内创建 Hello.cpp 文件,内容如下:

#include <iostream>

int main()
{
    cout<<"Hello world!"<<endl;
    cin.get();
    return 0;
}

 2、在标题栏中选择“文件”,再选择“打开文件夹”,选择刚才创建的“ProjectTest”。会弹出下面对话框:

3、按照下图一次选中

弹出下面对话框,选择红框部分

再选择第一个

会有报错,先不管。

三、配置 json 文件

在 .vscode 文件夹下创建 tasks.jsonlaunch.json 两个文件。代码分别如下:

{
    "version": "2.0.0",
    "command": "g++",
    "args": ["-g","${file}","-o","${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
        }
    }
}

 

{
    // 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) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",// miDebugger的路径,注意这里要与MinGw的路径对应
            "preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

四、运行

配置完成之后,重启 vs code。单击下图中的绿色的按钮,即可完成exe的生成和调试。

 

 

(SAW:Game Over!)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值