vscode 创建 运行c++ 项目

1 扩展 install c++

2.1安装 mingw g++

下载

MinGW-w64 - for 32 and 64 bit Windows - Browse Files at SourceForge.net

win32下载地址

Download x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z (MinGW-w64 - for 32 and 64 bit Windows)

2.2 把 文件夹 bin 路径 添加到环境变量 重启电脑

3 创建项目文件夹 -> 项目目录结构

test_c

-- .vscode

-- tasks.json

-- main.cpp

4 tasks.json

复制代码
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",
            "problemMatcher": []
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\app_install\\mingw\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ]
}

4 main.cpp 测试

cpp 复制代码
#include <iostream>

int main() {
    std::cout << "hello" << std::endl;
    return 0;
}

6 F5 或 ctrl+shift+b 运行(只是生成exe文件)

生成 main.exe

7 在vscode终端运行

.\main.exe

相关推荐
十五年专注C++开发3 分钟前
达梦数据库在Linux备份报错 -8003: 缺少本地或者远程归档 解决方案
数据库·c++·dm·备份复原
yy_xzz21 分钟前
【Linux开发】I/O 复用:select 模型
linux·c++·select
小肝一下28 分钟前
每日两道力扣,day6
数据结构·c++·算法·leetcode·双指针·hot100
ambition2024234 分钟前
【算法详解】飞机降落问题:DFS剪枝解决调度问题
c语言·数据结构·c++·算法·深度优先·图搜索算法
I Promise3437 分钟前
C++ 基础数据结构与 STL 容器详解
开发语言·数据结构·c++
旖-旎1 小时前
链表(两两交换链表中的节点)(2)
数据结构·c++·学习·算法·链表·力控
Reuuse1 小时前
基于 C++ 的网页五子棋对战项目实战
开发语言·c++
REDcker1 小时前
Android Bionic Libc 原理与实现综述
android·c++·c·ndk·native·bionic
我能坚持多久1 小时前
利用Date类的实现对知识巩固与自省
开发语言·c++