VSCode 配置C ++ 环境


前言

掌握VSCode配置C++ 开发环境

  1. 下载VScode

  2. 安装cpptools工具

  3. 下载MinGW

  4. 配置环境变量

  5. 使用简单的.cpp文件配置C++环境

  6. 运行


提示:以下是本篇文章正文内容,下面案例可供参考

一、下载安装VsCode

https://code.visualstudio.com/Download
在这里插入图片描述

下载自己需要的系统版本

二、安装cpptools工具

打开vscode ,在应用市场中搜索cpptools,并且进行安装
在这里插入图片描述

在文本框中输入cpptools
在这里插入图片描述
在这里插入图片描述

三.下载MinGW,安装g++ 运行环境

下载地址:https://sourceforge.net/projects/mingw-w64/files/
在这里插入图片描述

安装MinGW:下载后是一个7z的压缩包,解压后移动到你想安装的位置即可,我这里的目录是D:\gcc

四.配置环境变量

在这里插入图片描述
打开cmd 命令行,运行g++,查看环境变量是否配置成功
在这里插入图片描述
出现如上的提示,这说明本机的g++ 环境变量配置成功

五.编写HelloWorld

1.新建C++ 空文件夹
2.用vsCode 打开这个空文件作为项目根目录,以当前日期新建一个空文件夹,然后在这个空文件夹下面新建一个HelloWorld.cpp

#include <iostream>
using namespace std;
int main()
{
    cout << "Hello, world!" << endl;
    system("pause");
    return 0;
}

六:运行配置

在这里插入图片描述
launch.json

{
    // 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": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "externalConsole": false,        //强调一下,我习惯用vscode自带的终端,所以你不习惯可以改为true
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\gcc\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "task g++"
        }
    ]

}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "task g++",    //修改此项
            "command": "D:\\gcc\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
				"cwd": "D:\\gcc\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build"
        }
    ]
}

配置好以后在运行HelloWorld.cpp
在这里插入图片描述
运行成功,到这里c++开发环境 配置成功
参考文献:
https://www.cnblogs.com/bpf-1024/p/11597000.html

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值