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++开发7 分钟前
设计模式之单例模式(二): 心得体会
开发语言·c++·单例模式·设计模式
?!71426 分钟前
算法打卡第18天
c++·算法
zh_xuan42 分钟前
c++ std::pair
开发语言·c++
CodeWithMe1 小时前
【C/C++】EBO空基类优化介绍
开发语言·c++
love530love1 小时前
【PyCharm必会基础】正确移除解释器及虚拟环境(以 Poetry 为例 )
开发语言·ide·windows·笔记·python·pycharm
k要开心1 小时前
从C到C++语法过度1
开发语言·c++
whoarethenext2 小时前
使用 C/C++的OpenCV 实时播放火柴人爱心舞蹈动画
c语言·c++·opencv
能工智人小辰2 小时前
Codeforces Round 509 (Div. 2) C. Coffee Break
c语言·c++·算法
梦星辰.2 小时前
VSCode CUDA C++进行Linux远程开发
linux·c++·vscode
whoarethenext3 小时前
C++ OpenCV 学习路线图
c++·opencv·学习