| by XianKa | No comments

VScode配置g++编写c++

  1. 将g++添加到环境遍历
  2. 安装插件”code runner”
  3. 设置-插件-run code configuration-Run in terminal 勾选上(否则如果程序里有输入等待将无法继续)
  4. 下载微软官方插件C/C++ 以便于调试
  5. 在目录下的.vs文件夹里面生成:launch.json/tasks.json
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            
            
            "program": "{fileDirname}/{fileBasenameNoExtension}.exe",
            
            
            //"program": "enter program name, for example {workspaceFolder}/a.exe",              "args": [],              "stopAtEntry": false,              "cwd": "{workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            //"miDebuggerPath": "/path/to/gdb",
            "miDebuggerPath": "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/gdb.exe",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

 

{
    "version": "2.0.0",
    "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
    }
    }
}
  •  若引用”bits/stdc++.h报错。可能是因为默认complier是clang,在用户设置里更改,添加一句:
    "C_Cpp.default.compilerPath": "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/g++.exe",

    就好了。

  • .vs文件夹可以放在常用目录的根部,对所有子目录均可用
  • 若要快速建立配置文件,可以自己生成一个用户代码片段

     

发表评论