0xFF 写在前面
感谢 hinin 对我的技术指导以及 ltl0825 和 Charllote_ 在使用配置 VsCode 的过程中对我文章的勘误与补充。
0x01 安装 MinGW
link 下载,在下载中点击下图安装包下载,
将这个链接复制(等会会用到),
如果弹出此弹窗,就说明已经有 MinGW,直接跳过下载即可(点击 Cancel),
下载完成后在控制面板中搜索 查看高级系统设置,
点击环境变量,
点击系统变量中的 Path 变量,点击编辑,
点击新建,接着将刚刚保存的地址复制进去。
测试:按 Win + R 调出命令指示符,输入 cmd,输入 g ++ --veresion,若弹出如下图类似的字符,即设置成功。
0x02 安装 VsCode
今入官网(link)并点击对应的版本安装(如果你是管理员,则请安装 System Installer 版,否则安装 User Installer 版),安装好之后点击安装包安装。
0x03 必要的配置
安装完成后按 Ctrl + Shift + X,下载如下插件:
- Chinese (Simplified) (简体中文),进行必要的汉化。
- OI Runner ++ ,可以用于运行你的程序(文件路径必须无中文,否则会乱码引起错误)。
- C/C++,将 C/C++ 的语言支持添加到 Visual Studio 代码中,包括编辑(IntelliSense)和调试功能。
- Competitive Programming Helper (cph),可以直接在左侧窗口输入样例和并测试。
- Error Lens:改进错误、警告和其他语言诊断的突出显示。
0x04 运行文件
方法 1
点击左侧的三条竖线,点击 "+ Create Problem",并在第一个框中输入样例输入,第二个框中输入样例输出,点击 Run 即可运行。
如果显示 Passed 就是已经通过,如果是 Failed 就是答案错误,如果输出了 SEGTERM 就是输出过多或死循环 RE,TLE 了就直接停摆了。
方法 2
容易发现,法 1 无法进行死循环输出或判断代码是否 RE 或 TLE,所以此处给出另一种方法:点击文件,点击右上角的三角,接着点击 Launch OI Runner ++ ,在下面的窗口的 Input 输入样例输入,点击两个叠起来的三角,就可以运行,可以应用于死循环和 RE,但要求文件路径为全英文,如图(建议使用深色主题,否则浅色的运行按钮看不见):
0x04 luogu 刷题必备
- 安装 vscode-luogu,之后跟随引导登录;
- 如果要查看 Luogu 里的题目时 先按 Ctrl + Alt + G,接着再按 P 并输入题号,可以弹出题目内容,点击“传送到 cph”,进入三条杠运行即可;
- 需要提交题目时,按 Ctrl + Alt + G,接着按 S 再输入题号并选择语言即可提交代码。
0x05 缺省源设置
点击左下角设置,点击 "代码片段",在上方搜索框中输入 cpp.json,
这是默认情况:- {
- // 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"
- // }
- }
复制代码 这里给出我的缺省源:- {
- "QWQ": {
- "prefix": "Problem",
- "body": [
- "#include <bits/stdc++.h>",
- "#define PII pair <int, int>",
- "#define LL long long",
- "#define ST string",
- "#define DB double",
- "",
- "#define fr(x, y, z) for(int x = y; x <= z; x ++ )",
- "#define dfr(x, y, z) for(int x = y; x >= z; x -- )",
- "",
- "using namespace std;",
- "",
- "const int N = 0;",
- "",
- "signed main()",
- "{",
- " ios::sync_with_stdio(false);",
- " cin.tie(0);",
- "",
- " return 0;",
- "}",
- ""
- ]
- },
- "QAQ": {
- "prefix": "Contest",
- "body": [
- "#include <bits/stdc++.h>",
- "#define PII pair <int, int>",
- "#define LL long long",
- "#define ST string",
- "#define DB double",
- "",
- "#define fr(x, y, z) for(int x = y; x <= z; x ++ )",
- "#define dfr(x, y, z) for(int x = y; x >= z; x -- )",
- "",
- "using namespace std;",
- "",
- "const int N = 0;",
- "",
- "signed main()",
- "{",
- " freopen(".in", "r", stdin);",
- " freopen(".out", "w", stdout);",
- "",
- " ios::sync_with_stdio(false);",
- " cin.tie(0);",
- "",
- " return 0;",
- "}",
- ""
- ]
- }
- }
复制代码 在 cpp 程序中,若是我的缺省源,输入 Problem 或 Contest 就会激活缺省源,具体效果如图:
如果觉得手动打缺省源太累了的话,可以使用以下代码:
[code]#include using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; bool flg = 1; while(1) { getline(cin,s); if(s[0] == '~') break; if(!flg) cout |