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

相关推荐
AI视觉网奇13 分钟前
ue ‘vits_native’ 插件加载失败 ue ‘xxx’ 插件加载失败
c++·笔记·ue5
cuijiecheng201815 分钟前
将unsigned char *或unsigned char []转换为std::string
开发语言·c++·算法
cpp_250119 分钟前
P1957 口算练习题
数据结构·c++·算法·题解·洛谷
熊猫钓鱼>_>22 分钟前
Makefile应用场景实践日志:构建高效C/C++项目工作流
c语言·c++·bug·mfc·makefile·编译·kmp
Grimmjow33 分钟前
在栈/堆上创建并初始化C++对象
c++
全干工程师—44 分钟前
在liunx下使用VScode检测到 #include 错误。请更新 includePath问题的解决方法
ide·vscode·编辑器
.简.简.单.单.1 小时前
Design Patterns In Modern C++ 中文版翻译 第二十三章 模板方法
开发语言·c++·设计模式
君义_noip1 小时前
信息学奥赛一本通 1644:【例 4】佳佳的 Fibonacci
c++·数论·信息学奥赛·csp-s
小龙报1 小时前
【算法通关指南:算法基础篇 】模拟算法专题:1. 铺地毯 2. 回文日期 3. 扫雷
c语言·数据结构·c++·算法·动态规划·知识图谱·visual studio