vscode配置c/c++环境

2022年4月4日 21:25 ry 756

下载minw64,链接地址链接:https://pan.baidu.com/s/1J-aGQjIskRZORyJVV4e_Ig 提取码:wy5h,下载解压缩后,配置环境变量,点开设置,搜索环境变量,如图

点击环境变量,

把压缩的bin目录的路径复制上去,我的是这个路径

C:\Users\14499\Desktop\mingw64\bin

然后点击确定,确定,安装vscode,下载c/c++插件,run code插件,新疆一个test.cpp文件,写上代码如下

#include<iostream>
using namespace std;
int main()
{
    cout<<"hello,world!"<<endl;
    system("pause");
    return 0;
}

按ctrl+c保存,点击run and debug按钮,如图

然后弹出launch.json,编辑该文件,代码如下

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc",
            "type": "cppdbg",
            "request": "attach",
            "program": "输入程序名称,例如 ${workspaceFolder}/a.exe",
            "processId": "${command:pickRemoteProcess}",
            "pipeTransport": {
                "debuggerPath": "/usr/bin/gdb",
                "pipeProgram": "${env:windir}\\system32\\bash.exe",
                "pipeArgs": ["-c"],
                "pipeCwd": ""
            },
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
       
        {
            "name": "g++.exe",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Users\\14499\\Desktop\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++"
        }
    ]
}

这里记得把自己的电脑用户名改成自己的即可,编辑task.json,代码如下

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "gcc",
            "command": "C:\\Users\\14499\\Desktop\\mingw64\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        },
        {
            "type": "cppbuild",
            "label": "g++",
            "command": "C:\\Users\\14499\\Desktop\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$g++"
            ],
            "group": "build",
            "detail": "编译器: C:\\Users\\14499\\Desktop\\mingw64\\bin\\g++.exe"
        }
    ],
    "version": "2.0.0"
}

同样,用户名改成自己的即可,按ctrl+c保存,然后右键运行,如图

最后结果如下

如果上述代码帮助您很多,可以打赏下以减少服务器的开支吗,万分感谢!

欢迎发表评论~

点击此处登录后即可评论


评论列表
暂时还没有任何评论哦...

赣ICP备2021001574号-1

赣公网安备 36092402000079号