简单配置VScode轻量级C++竞赛环境

发布于:2024-07-05 ⋅ 阅读:(11) ⋅ 点赞:(0)

1. 安装拓展

在这里插入图片描述
Chinese是中文,需要重启才可以运行,C/C++拓展只是进行语法代码提示,不需要进行任何配置修改,默认即可。

2. 创建文件

在这里插入图片描述
如上图创建好各级文件夹,其中C++是工作文件夹,.vscode是配置文件夹,里面建一个tasks.json文件,然后把下面内容复制进去

{
	"version": "2.0.0",
	"tasks": [
		{
            "label": "build",
            "type": "shell",
            "command": "g++", // 如果没有配置环境变量可以直接改成g++.exe的文件路径
            "args": [
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-g",
                "-Wall",
                "-fexec-charset=GBK",
                "-std=c++11"
            ],
            "group": "build",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "problemMatcher": "$gcc"
        },
		{
            "label": "run",
            "type": "shell",
            "dependsOn": "build",
            "command": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            }
        }
	]
}

3. 绑定快捷键

在键盘快捷方式中搜索任务,找到任务:运行测试任务,配置快捷键,看个人习惯配置,我习惯是 ctrl + r
在这里插入图片描述
至此,环境就配置好了,通过快捷键运行代码,会在终端进行输入输出交互。注意,这样配置是没有debug能力的,不过竞赛选手普遍都是肉眼debug,不需要这个功能。

4. 刷题模板

配置用户代码段,选择cpp,然后把下面的内容复制进去,快捷键我配置的是acm,这样新创建一个cpp文件,输入acm回车就可以直接补全模板,如果想自定义的话也可以自行添加。

{
	// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
	// same ids are connected.
	// Example:
	// "Print to console": { 代码段名称
	// 	"prefix": "log", 代码段触发关键字
	// 	"body": [ 代码段主体
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console" 代码段介绍
	// }
	"template": {
		"prefix": "acm",
		"body": [
			"#pragma GCC optimize(3, \"Ofast\", \"inline\")",
			"#include<bits/stdc++.h>",
			"#define int long long",
			"#define x first",
			"#define y second",
			"#define pc putchar",
			"#define debug(x) cerr << #x\" = \" << x << '\\n';",
			"using namespace std;",
			"inline int rd() { int X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X;}",
			"inline void wr(int x) { if (x < 0) pc('-'), x = -x; if (x > 9) wr(x / 10); pc(x % 10 + '0');}",
			"",
			"void solve()",
			"{",
			"    $0",
			"}",
			"",
			"signed main()",
			"{",
			"    int _ = 1;",
			"    // cin >> _;",
			"    while (_ --) solve();",
			"    return 0;",
			"}"
		],
		"description": "template of acm"
	}
}

5. 鼠标滚轮调节字体大小

设置里面搜索font,找到如下选项,点击在setting.json中编辑
在这里插入图片描述
在json文件中加入editor.mouseWheelZoom": true即可
在这里插入图片描述
后续想到什么好的功能会继续更新~


网站公告

今日签到

点亮在社区的每一天
去签到