ACM VSCode 配置(备份)

效果

TIM-20190911170343.png

一 安装gcc并添加到PATH

二 配置

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

    • c_cpp_properties.json
    {
      "configurations": [
          {
              "name": "MinGW64",
              "intelliSenseMode": "gcc-x64",
              "compilerPath": "C:/MinGw/bin/g++.exe",
              "includePath": [
                  "${workspaceFolder}"
              ],
              "cppStandard": "c++14"
          }
      ],
      "version": 4
    

}:hexoPostRenderEscape–>
- launch.json
<!–hexoPostRenderEscape:

{
“version”: “0.2.0”,
“configurations”: [

    &#123;   
        <span class="hljs-attr">&quot;name&quot;</span>: <span class="hljs-string">&quot;C++ Launch (GDB)&quot;</span>,
        <span class="hljs-attr">&quot;type&quot;</span>: <span class="hljs-string">&quot;cppdbg&quot;</span>,
        <span class="hljs-attr">&quot;request&quot;</span>: <span class="hljs-string">&quot;launch&quot;</span>,
        <span class="hljs-attr">&quot;targetArchitecture&quot;</span>: <span class="hljs-string">&quot;x64&quot;</span>,
        <span class="hljs-attr">&quot;program&quot;</span>: <span class="hljs-string">&quot;$&#123;fileDirname&#125;/$&#123;fileBasenameNoExtension&#125;.exe&quot;</span>,
        <span class="hljs-attr">&quot;args&quot;</span>: [ ],
        <span class="hljs-attr">&quot;stopAtEntry&quot;</span>: <span class="hljs-literal">false</span>,
        <span class="hljs-attr">&quot;cwd&quot;</span>: <span class="hljs-string">&quot;$&#123;fileDirname&#125;/&quot;</span>,
        <span class="hljs-attr">&quot;externalConsole&quot;</span>: <span class="hljs-literal">true</span>,
        <span class="hljs-attr">&quot;internalConsoleOptions&quot;</span>: <span class="hljs-string">&quot;neverOpen&quot;</span>,
        <span class="hljs-attr">&quot;MIMode&quot;</span>: <span class="hljs-string">&quot;gdb&quot;</span>,
        <span class="hljs-attr">&quot;miDebuggerPath&quot;</span>: <span class="hljs-string">&quot;C:/MinGw/bin/gdb.exe&quot;</span>,
        <span class="hljs-attr">&quot;setupCommands&quot;</span>: [
            &#123;
                <span class="hljs-attr">&quot;description&quot;</span>: <span class="hljs-string">&quot;Enable pretty-printing for GDB&quot;</span>,
                <span class="hljs-attr">&quot;text&quot;</span>: <span class="hljs-string">&quot;-enable-pretty-printing&quot;</span>,
                <span class="hljs-attr">&quot;ignoreFailures&quot;</span>: <span class="hljs-literal">true</span>
            &#125;
        ],
        <span class="hljs-attr">&quot;preLaunchTask&quot;</span>: <span class="hljs-string">&quot;Compile&quot;</span> 
    &#125;
]

}

:hexoPostRenderEscape–>

- tasks.json
<!--hexoPostRenderEscape:<pre><code class="hljs json">&#123;
<span class="hljs-attr">&quot;version&quot;</span>: <span class="hljs-string">&quot;2.0.0&quot;</span>,
<span class="hljs-attr">&quot;tasks&quot;</span>: [
    &#123;
        <span class="hljs-attr">&quot;label&quot;</span>: <span class="hljs-string">&quot;Compile&quot;</span>,
        <span class="hljs-attr">&quot;command&quot;</span>: <span class="hljs-string">&quot;g++&quot;</span>,
        <span class="hljs-attr">&quot;args&quot;</span>: [
            <span class="hljs-string">&quot;-g&quot;</span>,
            <span class="hljs-string">&quot;$&#123;file&#125;&quot;</span>,   <span class="hljs-comment">// 指定编译源代码文件</span>
            <span class="hljs-string">&quot;-o&quot;</span>,
            <span class="hljs-string">&quot;$&#123;fileDirname&#125;/$&#123;fileBasenameNoExtension&#125;.exe&quot;</span>, <span class="hljs-comment">// 指定输出文件名,不加该参数则默认输出a.exe</span>
            <span class="hljs-comment">//&quot;-O2&quot;,      // 优化级别</span>
            <span class="hljs-comment">//&quot;-ggdb3&quot;,   // 生成和调试有关的信息</span>
            <span class="hljs-comment">//&quot;-Wall&quot;,    // 开启额外警告</span>
            <span class="hljs-comment">//&quot;-static-libgcc&quot;,   // 静态链接</span>
            <span class="hljs-comment">//&quot;-std=c++14&quot;,       // 使用c++17标准</span>
            <span class="hljs-comment">//&quot;-finput-charset=UTF-8&quot;,    //输入编译器文本编码 默认为UTF-8</span>
            <span class="hljs-comment">//&quot;-fexec-charset=GB18030&quot;,   //输出exe文件的编码</span>
            <span class="hljs-comment">//&quot;-D _USE_MATH_DEFINES&quot;</span>
        ],
        <span class="hljs-attr">&quot;problemMatcher&quot;</span>: &#123;
            <span class="hljs-attr">&quot;owner&quot;</span>: <span class="hljs-string">&quot;cpp&quot;</span>,
            <span class="hljs-attr">&quot;fileLocation&quot;</span>: [
                <span class="hljs-string">&quot;absolute&quot;</span>,
            ],
            <span class="hljs-attr">&quot;pattern&quot;</span>: &#123;
                <span class="hljs-attr">&quot;regexp&quot;</span>: <span class="hljs-string">&quot;^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$&quot;</span>,
                <span class="hljs-attr">&quot;file&quot;</span>: <span class="hljs-number">1</span>,
                <span class="hljs-attr">&quot;line&quot;</span>: <span class="hljs-number">2</span>,
                <span class="hljs-attr">&quot;column&quot;</span>: <span class="hljs-number">3</span>,
                <span class="hljs-attr">&quot;severity&quot;</span>: <span class="hljs-number">4</span>,
                <span class="hljs-attr">&quot;message&quot;</span>: <span class="hljs-number">5</span>
            &#125;
        &#125;,
        <span class="hljs-attr">&quot;type&quot;</span>: <span class="hljs-string">&quot;shell&quot;</span>,            
        <span class="hljs-attr">&quot;group&quot;</span>: &#123;
            <span class="hljs-attr">&quot;kind&quot;</span>: <span class="hljs-string">&quot;build&quot;</span>,
            <span class="hljs-attr">&quot;isDefault&quot;</span>: <span class="hljs-literal">true</span>
        &#125;
    &#125;
]

}:hexoPostRenderEscape–>

  • 以上主要用于需要断点调试的时候
  • 快速编译可以安装coderunner插件
    1. 安装coderunner
    2. .vscode新建setting.json
    {
      "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
    

}:hexoPostRenderEscape–>

三 快速编辑

  • 文件->首选项->用户代码片段->cpp.json中添加
{
	"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"
	}
}