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!!!

相关推荐
Three~stone4 分钟前
IDEA编码实用技巧
java·ide·intellij-idea
aleluye1 小时前
vscode颜色配置
ide·vscode·编辑器
iiiiiankor5 小时前
vscode/cursor中python运行路径设置 &&模块导入问题
ide·vscode·python
大博士.J5 小时前
vscode终端不识别npm 无法解析npm
ide·vscode·npm
我认不到你5 小时前
油候插件、idea、VsCode插件推荐(自用)
java·前端·vscode·react.js·typescript·编辑器·intellij-idea
烂蜻蜓6 小时前
巧用 VSCode 开启 Vue 开发之旅
ide·vue.js·vscode
ONLYOFFICE6 小时前
如何将 Google Gemini AI 连接到 ONLYOFFICE 编辑器
人工智能·编辑器
ronvicki6 小时前
VSCODE右下角切换环境没用
vscode·编辑器
寒山李白6 小时前
VSCode下载安装指南
ide·vscode·开发工具
❆VE❆7 小时前
【工具分享】vscode+deepseek的接入与使用
ide·vscode·编辑器·ai编程·工具·deepseek