ACM VSCode 配置(备份)

效果

TIM-20190911170343.png
TIM-20190911170343.png

一 安装gcc并添加到PATH

二 配置

  • 在储存代码的目录新建一个文件夹.vscode, 并新建三个文件

    • c_cpp_properties.json

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      {
      "configurations": [
      {
      "name": "MinGW64",
      "intelliSenseMode": "gcc-x64",
      "compilerPath": "C:/MinGw/bin/g++.exe",
      "includePath": [
      "${workspaceFolder}"
      ],
      "cppStandard": "c++14"
      }
      ],
      "version": 4
      }
    • launch.json

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      {
      "version": "0.2.0",
      "configurations": [

      {
      "name": "C++ Launch (GDB)",
      "type": "cppdbg",
      "request": "launch",
      "targetArchitecture": "x64",
      "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
      "args": [ ],
      "stopAtEntry": false,
      "cwd": "${fileDirname}/",
      "externalConsole": true,
      "internalConsoleOptions": "neverOpen",
      "MIMode": "gdb",
      "miDebuggerPath": "C:/MinGw/bin/gdb.exe",
      "setupCommands": [
      {
      "description": "Enable pretty-printing for GDB",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
      }
      ],
      "preLaunchTask": "Compile"
      }
      ]
      }
    • tasks.json

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      {
      "version": "2.0.0",
      "tasks": [
      {
      "label": "Compile",
      "command": "g++",
      "args": [
      "-g",
      "${file}", // 指定编译源代码文件
      "-o",
      "${fileDirname}/${fileBasenameNoExtension}.exe", // 指定输出文件名,不加该参数则默认输出a.exe
      //"-O2", // 优化级别
      //"-ggdb3", // 生成和调试有关的信息
      //"-Wall", // 开启额外警告
      //"-static-libgcc", // 静态链接
      //"-std=c++14", // 使用c++17标准
      //"-finput-charset=UTF-8", //输入编译器文本编码 默认为UTF-8
      //"-fexec-charset=GB18030", //输出exe文件的编码
      //"-D _USE_MATH_DEFINES"
      ],
      "problemMatcher": {
      "owner": "cpp",
      "fileLocation": [
      "absolute",
      ],
      "pattern": {
      "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
      "file": 1,
      "line": 2,
      "column": 3,
      "severity": 4,
      "message": 5
      }
      },
      "type": "shell",
      "group": {
      "kind": "build",
      "isDefault": true
      }
      }
      ]
      }
  • 以上主要用于需要断点调试的时候

  • 快速编译可以安装coderunner插件

    1. 安装coderunner
    2. .vscode新建setting.json
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      {
      "code-runner.runInTerminal": true,
      "code-runner.fileDirectoryAsCwd": true,
      "code-runner.executorMap": {
      "c": "gcc $fileName -o build/$fileNameWithoutExt.exe && .\\build\\$fileNameWithoutExt.exe",
      "cpp": "g++ $fileName -o build/$fileNameWithoutExt.exe -Wall -O2 -static-libgcc -std=c++14 && .\\build\\$fileNameWithoutExt.exe"
      },
      "code-runner.preserveFocus": false,
      "code-runner.saveFileBeforeRun": true
      }

三 快速编辑

  • 文件->首选项->用户代码片段->cpp.json中添加
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    {
    "acminit" : {
    "prefix": "acminit",
    "body": [
    "// Author : Wqr_",
    "// Time : ${CURRENT_YEAR_SHORT}/${CURRENT_MONTH}/${CURRENT_DATE}",
    "#include<bits/stdc++.h>",
    "#define iofuck std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)",
    "#define INF 0x3f3f3f3f",
    "using namespace std;",
    "typedef long long ll;",
    "int main(){",
    " $0",
    "}"
    ],
    "description": "acminit"
    },
    "filein" : {
    "prefix": "filein",
    "body": [
    "#ifndef ONLINE_JUDGE",
    "freopen(\"in.txt\",\"r\",stdin);",
    "#endif"
    ],
    "description": "filein"
    }

    }