vscode配置C/C++运行环境

图片[1]-vscode配置C/C++运行环境-铭心博客
图片[2]-vscode配置C/C++运行环境-铭心博客
打开控制台,切换到调试控制台,看到有 hello world,就配置成功啦!
 
  但是,问题来了,它没有弹出我们想要的黑漆漆的窗口怎么办?没有内味!
  欸,不要着急,我们可以看见有一个.vscode文件夹,里面已经生成了一个tasks.json,我们再创建一个launch.json
{
    // 使用 IntelliSense 了解相关属性。
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,    // 改为true,就可以弹出控制台啦!!!!
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe",  // 设置为自己的 mingw\\bin\\gdb.exe 路径
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件"
        }
    ]
}

  再附上我自己自定义的settings.json文件,这个文件可以让你的设定在这个文件夹内有效,不影响vscode全局使用。

同理,一个文件夹可以创建一个.vscode文件夹来自定义局部设定,在使用git的时候,还可以通过.gitignore阻止.vscode的上传!

{
    "files.autoSave": "onFocusChange",
    "editor.fontFamily": "Consolas, 'Courier New', monospace",
    "editor.fontSize": 13,
    "editor.fontWeight": "bold",
    "editor.formatOnSave": true,
    "editor.unicodeHighlight.allowedCharacters": {
        "!": true,
        "。": true,
        ":": true,
        "(": true,
        ")": true,
        ",": true
    },
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "explorer.sortOrder": "type",
    "files.associations": {
        "ostream": "cpp"
    },
}

c

  c大致上和C++相同,唯一差别就是在.vscode文件夹内配置的设置问题,c语言的则改为如下:
  c_cpp_properties.json中的compilerPath则改为gcc.exe
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "D:\\MinGW\\bin\\gcc.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "${default}"
        }
    ],
    "version": 4
}
tasks.json中的command改为gcc.exe
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 生成活动文件",
            "command": "D:\\MinGW\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}
图片[3]-vscode配置C/C++运行环境-铭心博客
© 版权声明
THE END
喜欢就支持一下吧!
点赞97 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容