vscode 编译运行C++

1.首先,你得下载vscode

官网地址

2.其次,你需要c++的编译运行环境

此处推荐Mingw    官网地址

3.配置C++ 的编译运行环境

在你经常要写C++项目的文件中新建文件夹.vscode

文件夹中新建3个文件

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
        "name": "(Windows) Launch",
        "type": "cppvsdbg",
        "request": "launch",
        "program": "cmd",
        "preLaunchTask": "g++",//这里需要换成你task.json中的任务名
        "args": [
          "/C",
          "${file}.exe",
          "&",
          "echo.",
          "&",
          "pause"
        ],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole":true
        }
    ]
  
}

tasks.json

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

c_cpp_properties.json

注意: 其中的目录为你安装mingw的 路径

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++",
                "D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/mingw32",
                "D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/backward",
                "D:/C++/environment/lib/gcc/mingw32/8.2.0/include",
                "D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/tr1",
                "D:/C++/environment/mingw32/lib"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "browse": {
                "path": [
                    "${workspaceRoot}",
                    "D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++",
                    "D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/mingw32",
                    "D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/backward",
                    "D:/C++/environment/lib/gcc/mingw32/8.2.0/include",
                    "D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/tr1",
                    "D:/C++/environment/mingw32/lib"
                ]
            },
            "compilerPath": "D:\\C++\\environment\\bin\\gcc.exe",
            "cStandard": "gnu18",
            "cppStandard": "gnu++14"
        }
    ],
    "version": 4
}

 

使用结果

新建C++文件

#include<bits/stdc++.h>
using namespace std;
int main() {
    cout << "hello" << endl;
    return 0;
}

按F5编译运行

完美!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值