记一次VSCode上C++的配置

重点参考:这篇

其中在调试模块出了问题,总是提示什么进程运行时候以外退出,要安装.Net4.6.2。

去网上下载安装.Net4.6.2又无法安装成功,总是说Windows Installer不能用。但是在services.msc里看,这个服务是开启的没问题。最后只好在腾讯电脑管家的软件管理里面安装它。

 

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "E:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

 

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/build/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            // 这里要与你在 tasks.json 中配置的 label 一致
            "preLaunchTask": "compile",
        }
    ]
}

 

launch.json右侧工作区添加

{
    // 在终端中运行编译命令,否则我们无法与程序通过标准输入交互
    "code-runner.runInTerminal": true,
    // 如果你全局设置中的默认终端是 WSL 之类的,那么可以在工作区设置中改回 PowerShell
    "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
    // 运行代码之前清除之前的输出
    "code-runner.clearPreviousOutput": true,
    // 开启这个后在运行编译命令之前会自动 cd 至文件所在目录
    "code-runner.fileDirectoryAsCwd": true,
    // 因为上面那个选项会自动 cd,所以我删除了默认编译命令中的 cd 语句
    // 同时我将编译结果的输出目录修改为了同目录下的 build 文件夹
    // 不然源码文件和编译结果混杂在一个目录中非常杂乱(尤其是刷题时)
    // 这里只保留了 C 和 C++ 的编译命令,有需要其他语言的请自行添加
    "code-runner.executorMap": {
        "c": "gcc $fileName -o build/$fileNameWithoutExt && .\\build\\$fileNameWithoutExt",
        "cpp": "g++ $fileName -o build/$fileNameWithoutExt && .\\build\\$fileNameWithoutExt",
    },
    // 运行代码后切换焦点至终端,方便直接输入测试数据
    "code-runner.preserveFocus": false,
    // 在运行代码之前保存文件
    "code-runner.saveFileBeforeRun": true,
}

 

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "\"${file}\"",
                "-o",
                "\"${fileDirname}\\build\\${fileBasenameNoExtension}\""
            ],
            "presentation": {
                "reveal": "always",
                "panel": "shared",
                "focus": false,
                "echo": true
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": "absolute",
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

 

posted @ 2019-01-11 12:10  LauZyHou  阅读(994)  评论(0编辑  收藏  举报