关于vscode配置C/C++的配置文件问题

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:\\code\\MinGW\\bin\\g++.exe",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\code\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件 ver(1)"
        }
    ]
}

settings.json

{
    "C_Cpp.errorSquiggles": "Disabled",
    "files.associations": {
        "ostream": "cpp",
        "iostream": "cpp",
        "random": "cpp"
    }
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "D:\\code\\MinGW\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}/build/${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "编译器: D:\\code\\MinGW\\bin\\g++.exe"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件 ver(1)",
            "command": "D:\\code\\MinGW\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}/build/${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ]
}

在vscode选择打开的文件夹下新建一个build文件夹,可以把exe文件都放到里面,更加美观。

如果使用code runner,在它的设置中找到settings.json文件进行修改,如下

{
    "code-runner.executorMap":
        {
        "cpp": "cd $dir && g++ -std=c++11 $fileName -D LOCAL -o D:/code/C++/build/$fileNameWithoutExt.exe && D:/code/C++/build/$fileNameWithoutExt.exe"
        },//增添的的部分!!!路径改成自己建立的build文件夹,比如D:/code/C++/build(自己替换)
    "code-runner.runInTerminal": true,
    "code-runner.ignoreSelection": true,
    "c-cpp-compile-run.run-in-external-terminal": true,
    "workbench.iconTheme": "eq-material-theme-icons-palenight",
    "editor.fontSize": 18,
    "workbench.colorTheme": "Community Material Theme Palenight",
    "files.autoSave": "afterDelay",
    "extensions.ignoreRecommendations": true,
    "editor.hover.enabled": false,
    "editor.parameterHints.enabled": false,
    "terminal.integrated.scrollback": 1600,
    "bracket-pair-colorizer-2.depreciation-notice": false,
    "window.zoomLevel": 1
    
    
}

上一篇:VSCode让终端面板显示到右边


下一篇:VSCode 离线安装中文语言包