vscode在win10 / linux下的.vscode文件夹的配置 (c++/c)

系统方面配置自行查找

linux:

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/${fileBasenameNoExtension}.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build"
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": 
    [
        {
            "label": "build",//任务名,和lanuch.json中的"preLaunchTask":"build"一致
            "type": "shell",
            "command": "g++",
            "args":["-g","${workspaceRoot}/${fileBasenameNoExtension}.cpp","-o","${fileBasenameNoExtension}.out"],//要编译的文件mian_test.cpp,${workspaceRoot}表示vscode所打开的工作目录
            "problemMatcher":
            {
                "owner":"cpp",
                "fileLocation":["relative","${workspaceRoot}"],
                "pattern":
                {
                    "regexp": "^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$",
                    "file": 1,
                    "line":2,
                    "column":3,
                    "severity": 4,
                    "location": 2,
                    "message": 5
                }
            }
        }
 
    ]
}

win10:

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "preLaunchTask": "build",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/mingw/bin/gdb.exe", // 这里修改GDB路径为安装的mingw64的bin下的gdb.exe路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }]

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "windows": {
                "command": "g++",
                "args": [
                    "-ggdb",
                    "\"${file}\"",
                    "--std=c++11",
                    "-o",
                    "\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
                ]
            }
        }
    ]
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以按照以下步骤配置VS Code的C/C++环境: 1. 首先,确保你已经安装了VS Code编辑器和C/C++插件。你可以在VS Code扩展商店搜索并安装C/C++插件。 2. 安装GCC编译器。在Windows系统上,你可以安装MinGW-w64或者TDM-GCC。在macOS上,你可以使用Xcode Command Line Tools或者安装GCC。在Linux上,你可以使用默认的系统GCC编译器。 3. 打开VS Code,点击左侧的"扩展"按钮(或按下`Ctrl+Shift+X`),搜索并安装"C/C++"扩展。 4. 在VS Code中打开你的C/C++项目文件夹或者创建一个新的C/C++文件。 5. 点击左下角的"选择编译器"按钮,默认为`No Configuration`。选择"C/C++: GCC"编译器,如果你使用的是不同的编译器,可以选择相应的选项。 6. 创建一个`.vscode`文件夹,并在其中创建一个名为`c_cpp_properties.json`的文件。在这个文件中,你可以配置编译器路径和其他相关设置。例如,下面是一个示例配置: ```json { "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:/MinGW/include" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "C:/MinGW/bin/gcc.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64" } ], "version": 4 } ``` 7. 在VS Code中打开你的C/C++源代码文件,并开始编写代码。你可以使用调试器来调试程序,并且还有许多其他功能可供探索和使用。 这样,你就可以在VS Code中配置和使用C/C++环境了。根据你的操作系统和编译器选择,可能会有一些细微的差异,但是大体的步骤是相似的。希望对你有帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值