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

相关推荐
Brilliantwxx3 分钟前
【C++】 vector(代码实现+坑点讲解)
开发语言·c++·笔记·算法
kafei_*1 小时前
VScode 添加 UV虚拟环境方法
vscode·python·uv
叼烟扛炮1 小时前
C++第三讲:类和对象(中)
开发语言·c++·类和对象
KuaCpp1 小时前
C++新特性学习
c++·学习
墨染千千秋1 小时前
C/C++ Keywords
c语言·c++
ximu_polaris2 小时前
设计模式(C++)-行为型模式-中介者模式
c++·设计模式·中介者模式
CSCN新手听安3 小时前
【Qt】Qt窗口(八)QFontDialog字体对话框,QInputDialog输入对话框的使用,小结
开发语言·c++·qt
tumu_C4 小时前
用std::function减缓C++模板代码膨胀和编译压力的一个场景
开发语言·c++
Hical614 小时前
C++17 实战心得:那些真正改变我写代码方式的特性
c++
Hical615 小时前
实测:C++20 协程 vs Go Gin vs Rust Actix,谁的 Web 性能更强?
c++