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

相关推荐
人猿泰飞31 分钟前
【初识Trae】字节跳动推出的下一代AI原生IDE,重新定义智能编程
ide·ai-native·trae·ai原生ide
百锦再1 小时前
Android Studio开发 SharedPreferences 详解
android·ide·android studio
偶尔微微一笑1 小时前
AI网络渗透kali应用(gptshell)
linux·人工智能·python·自然语言处理·编辑器
timing9942 小时前
LVGL在VScode的WSL2中仿真
ide·vscode·编辑器
未来之窗软件服务3 小时前
声音分离人声和配乐-从头设计数字生命第4课——仙盟创梦IDE
ide·仙盟创梦ide·数字生命
躲在云朵里`3 小时前
IDEA搭建环境的五种方式
java·ide·intellij-idea
Zhuai-行淮3 小时前
vscode和git 踩坑
ide·git·vscode
Percep_gan4 小时前
解决重装idea后破解jerbel的问题
java·ide·intellij-idea
kooboo china.7 小时前
Tailwind CSS 实战:基于 Kooboo 构建企业官网页面(一)
前端·css·编辑器
Zww08918 小时前
出现delete CR eslint错误
vscode