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

相关推荐
额,不知道写啥。1 小时前
HAO的线段树(中(上))
数据结构·c++·算法
LYS_06182 小时前
C++学习(5)(函数 指针 引用)
java·c++·算法
ADDDDDD_Trouvaille2 小时前
2026.2.21——OJ95-97题
c++·算法
Once_day3 小时前
C++之《程序员自我修养》读书总结(4)
c语言·c++·编译和链接
tod1134 小时前
C++核心知识点全解析(二)
开发语言·c++·面试经验
载数而行5205 小时前
算法系列2之最短路径
c语言·数据结构·c++·算法·贪心算法
消失的旧时光-19435 小时前
C++ 多线程与并发系统取向(五)—— std::atomic:原子操作与状态一致性(类比 Java Atomic)
开发语言·jvm·c++·并发
低频电磁之道5 小时前
C++中预定义宏
开发语言·c++
fpcc5 小时前
并行编程实战——CUDA编程的Warp Vote
c++·cuda
fpcc5 小时前
并行编程实战——CUDA编程的Warp Shuffle
c++·cuda