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

相关推荐
猪在黑魔纹里29 分钟前
解决VSCode无法高亮、解析numpy中的部分接口(如pi、deg2rad)
ide·vscode·python·numpy
辣椒酱.1 小时前
vscode报错------控制台
vscode·编辑器
让梦想疯狂1 小时前
Visual Studio 自动格式化代码
ide·visual studio
code bean1 小时前
【CMake 】[第九篇] 解决 CMake + Visual Studio 中文乱码问题完整指南
ide·visual studio
AllinGold1 小时前
反重力Antigravity配置
ide
欢喜躲在眉梢里2 小时前
基于 openFuyao 社区的无硬件 UB 开发实战指南
运维·数据库·人工智能·vscode·ai·开发工具·go开发
自己的九又四分之三站台3 小时前
Manium:现代化的数学动画创作引擎(Manim 的可视化编辑器方向项目)
编辑器
粤M温同学3 小时前
VsCode快速打出console.log()方法设置
vscode·编辑器
阿关@3 小时前
Vscode中Python无法将pip/pytest”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
vscode·python·pip
忘带键盘了4 小时前
eclipse配置
java·ide·eclipse