Document

vscode c++ 配置

//vscode C++环境配置

常用插件 直接安装即可 安装完成后重启

cmake ;cmake tools;chinese (Simplified); c/c++;

关于环境配置的前提 MinGW

下载最新版本安装就可
https://sourceforge.net/projects/mingw-w64/files/
进入网页后,点击File,下滑,
ps:
SJLJ (setjmp / longjmp):可用于32位和64位较小的性能损失
DWARF (DW2,dwarf-2)只有32位可用 
SEH (零开销exception) 将可用于64位GCC 4.8。(推荐)

选择MinGW-W64 GCC-8.1.0下载(最新版本)
正常安装就行

win32及posix区别
//三个配置文件

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "你的本地路径/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

launch.json

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "(gdb) Launch",    // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg",         // 配置类型,这里只能为cppdbg
            "request": "launch",    // 请求配置类型,可以为launch(启动)或attach(附加)
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
            "args": [],                // 程序调试时传递给程序的命令行参数,一般设为空即可
            "stopAtEntry": false,     // 设为true时程序将暂停在程序入口处,一般设置为false
            "cwd": "${workspaceRoot}",// 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
            "environment": [],
            "externalConsole": true,// 调试时是否显示控制台窗口,一般设置为true显示控制台
            "MIMode": "gdb",
            "miDebuggerPath": "你的路径gdb.exe",// miDebugger的路径,注意这里要与MinGw的路径对应
            "preLaunchTask": "g++",    // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "g++",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe"
            ],
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            },
            "group": "build"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "你的路径g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "你的路径/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ]
}

程序运行

程序编写结束后,ctrl+s保存,F5运行程序
posted @ 2023-04-17 14:49  qdyaodao  阅读(46)  评论(0)    收藏  举报
Document