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

相关推荐
冷崖20 小时前
原子锁操作
c++·后端
旖旎夜光1 天前
C++(17)
c++·学习
Larry_Yanan1 天前
Qt多进程(三)QLocalSocket
开发语言·c++·qt·ui
superman超哥1 天前
仓颉语言中元组的使用:深度剖析与工程实践
c语言·开发语言·c++·python·仓颉
Lucas555555551 天前
现代C++四十不惑:AI时代系统软件的基石与新征程
开发语言·c++·人工智能
_MyFavorite_1 天前
cl报错+安装 Microsoft Visual C++ Build Tools
开发语言·c++·microsoft
charlie1145141911 天前
现代嵌入式C++教程:C++98——从C向C++的演化(2)
c语言·开发语言·c++·学习·嵌入式·教程·现代c++
zmzb01031 天前
C++课后习题训练记录Day55
开发语言·c++
李白同学1 天前
C++:继承
开发语言·c++
k***92161 天前
【C++】STL详解(九)—priority_queue的使用与模拟实现
开发语言·c++