VScode 运行C++ (经典hello world!)

1.安装 mingw64,路径F:/mingw64

2.vscode安装插件

  1. main.cpp
cpp 复制代码
// 写一个hello world程序 c++
#include <iostream>
using namespace std;
int main() {
    // 返回0,表示程序正常结束
    std::cout << "Hello, world!" << std::endl;
    std::cout << "这是我的第一个小小小小的程序!" << std::endl;
    return 0;
}

4.按下ctrl+shift+p,然后输入>C/C++

生成一个文件

c_cpp_properties.json

cpp 复制代码
{
    "configurations": [{
        "name": "Win32",
        "includePath": [
            "${workspaceFolder}/**",
            "F:/mingw64/include/**" // 根据实际安装路径修改
        ],
        "compilerPath": "F:/mingw64/bin/g++.exe",
        "intelliSenseMode": "windows-gcc-x64"
    }],
    "version": 4
}

lauch.json

cpp 复制代码
{
    "version": "0.2.0",
    "configurations": [{
        "name": "C++ Debug",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "gdb.exe",
        "preLaunchTask": "C++ Build"
    }]
}

settings.json

cpp 复制代码
{
    "files.associations": {
        "iostream": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "algorithm": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "fstream": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "typeinfo": "cpp"
    }
}

tasks.json

cpp 复制代码
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "C++ Build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe",
                "-std=c++17",
                "-Wall"
            ],
            "group": "build"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "F:/mingw64/bin/g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "F:/mingw64/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ]
}

5.运行

6.运行出来了第一个hello world!!!

相关推荐
君以思为故1 小时前
认识linux -- 编辑器vim以及编译器gcc/g++和Makefile文件
linux·编辑器·vim
数据饕餮1 小时前
faster-whisper热词详解与程序设计
ide·macos·xcode
歪歪1002 小时前
在C#中除了按属性排序,集合可视化器还有哪些辅助筛选的方法?
开发语言·前端·ide·c#·visual studio
尤超宇4 小时前
U-net 系列算法知识解读
编辑器
许泽宇的技术分享4 小时前
把 CLI 搬上 Web:在内网打造“可二开”的 AI IDE,为什么这条路更现实?
前端·ide·人工智能
2501_938791225 小时前
VsCode 远程模式 + 服务器:Github Copilot 安装后无法触发?原因解析
服务器·vscode·github
Eiceblue6 小时前
使用 Python 向 PDF 添加附件与附件注释
linux·开发语言·vscode·python·pdf
王RuaRua6 小时前
VScode C/C++环境配置
c语言·c++·vscode
宁雨桥6 小时前
VSCode插件开发实战:从零到发布的技术大纲
ide·vscode·编辑器
OpenTiny社区8 小时前
如何使用 TinyEditor 快速部署一个协同编辑器
前端·开源·编辑器·opentiny