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

相关推荐
墨小傲2 小时前
基于Linux下的vscode c/c++开发环境搭建详细教程
linux·c语言·vscode
淡漠的蓝精灵2 小时前
【2025】Sublime Text 4安装教程保姆级一键安装教程(附安装包)
其他·编辑器·sublime text
Percep_gan2 小时前
idea的使用小技巧,个人向
java·ide·intellij-idea
tan180°11 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
万千思绪15 小时前
【PyCharm 2025.1.2配置debug】
ide·python·pycharm
我在看世界16 小时前
家里vscode连公司内网vscede
vscode·ssh
不想迷路的小男孩19 小时前
Android Studio 中Palette跟Component Tree面板消失怎么恢复正常
android·ide·android studio
AlickLbc20 小时前
在phpstudy环境下配置搭建XDEBUG配合PHPSTORM的调试环境
ide·phpstorm
悠悠小茉莉20 小时前
Win11 安装 Visual Studio(保姆教程 - 更新至2025.07)
c++·ide·vscode·python·visualstudio·visual studio
SZ17011023120 小时前
华为云 银河麒麟 vscode远程连接
ide·vscode·华为云