找回密码
 立即注册
首页 业界区 业界 VsCode 使用指南(配置 + 美化)

VsCode 使用指南(配置 + 美化)

伏滢 2025-8-16 10:07:16
0xFF 写在前面

感谢 hinin 对我的技术指导以及 ltl0825  和 Charllote_ 在使用配置 VsCode 的过程中对我文章的勘误与补充。
0x01 安装 MinGW

link 下载,在下载中点击下图安装包下载,

将这个链接复制(等会会用到),
2.png

如果弹出此弹窗,就说明已经有 MinGW,直接跳过下载即可(点击 Cancel),
3.png

下载完成后在控制面板中搜索 查看高级系统设置
4.png

点击环境变量,
5.png

点击系统变量中的 Path 变量,点击编辑,
6.png

点击新建,接着将刚刚保存的地址复制进去。
7.png

测试:按 Win + R 调出命令指示符,输入 cmd,输入 g ++ --veresion,若弹出如下图类似的字符,即设置成功。
8.png

0x02 安装 VsCode

今入官网(link)并点击对应的版本安装(如果你是管理员,则请安装 System Installer 版,否则安装 User Installer 版),安装好之后点击安装包安装。
9.png

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 即可运行。
10.png

如果显示 Passed 就是已经通过,如果是 Failed 就是答案错误,如果输出了 SEGTERM 就是输出过多或死循环 RE,TLE 了就直接停摆了。
11.png

方法 2

容易发现,法 1 无法进行死循环输出或判断代码是否 RE 或 TLE,所以此处给出另一种方法:点击文件,点击右上角的三角,接着点击 Launch OI Runner ++ ,在下面的窗口的 Input 输入样例输入,点击两个叠起来的三角,就可以运行,可以应用于死循环和 RE,但要求文件路径为全英文,如图(建议使用深色主题,否则浅色的运行按钮看不见):
12.png

0x04 luogu 刷题必备


  • 安装 vscode-luogu,之后跟随引导登录;
  • 如果要查看 Luogu 里的题目时 先按 Ctrl + Alt + G,接着再按 P 并输入题号,可以弹出题目内容,点击“传送到 cph”,进入三条杠运行即可;
  • 需要提交题目时,按 Ctrl + Alt + G,接着按 S 再输入题号并选择语言即可提交代码。
0x05 缺省源设置

点击左下角设置,点击 "代码片段",在上方搜索框中输入 cpp.json,
13.png

这是默认情况:
  1. {
  2.         // Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
  3.         // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
  4.         // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
  5.         // same ids are connected.
  6.         // Example:
  7.         // "Print to console": {
  8.         //         "prefix": "log",
  9.         //         "body": [
  10.         //                 "console.log('$1');",
  11.         //                 "$2"
  12.         //         ],
  13.         //         "description": "Log output to console"
  14.         // }
  15. }
复制代码
这里给出我的缺省源:
  1. {
  2.         "QWQ": {
  3.                 "prefix": "Problem",
  4.                 "body": [
  5.                         "#include <bits/stdc++.h>",
  6.                         "#define PII pair <int, int>",
  7.                         "#define LL long long",
  8.                         "#define ST string",
  9.                         "#define DB double",
  10.                         "",
  11.                         "#define fr(x, y, z) for(int x = y; x <= z; x ++ )",
  12.                         "#define dfr(x, y, z) for(int x = y; x >= z; x -- )",
  13.                         "",
  14.                         "using namespace std;",
  15.                         "",
  16.                         "const int N = 0;",
  17.                         "",
  18.                         "signed main()",
  19.                         "{",
  20.                         "    ios::sync_with_stdio(false);",
  21.                         "    cin.tie(0);",
  22.                         "",
  23.                         "    return 0;",
  24.                         "}",
  25.                         ""
  26.                 ]
  27.         },
  28.         "QAQ": {
  29.                 "prefix": "Contest",
  30.                 "body": [
  31.                         "#include <bits/stdc++.h>",
  32.                         "#define PII pair <int, int>",
  33.                         "#define LL long long",
  34.                         "#define ST string",
  35.                         "#define DB double",
  36.                         "",
  37.                         "#define fr(x, y, z) for(int x = y; x <= z; x ++ )",
  38.                         "#define dfr(x, y, z) for(int x = y; x >= z; x -- )",
  39.                         "",
  40.                         "using namespace std;",
  41.                         "",
  42.                         "const int N = 0;",
  43.                         "",
  44.                         "signed main()",
  45.                         "{",
  46.                         "    freopen(".in", "r", stdin);",
  47.                         "    freopen(".out", "w", stdout);",
  48.                         "",
  49.                         "    ios::sync_with_stdio(false);",
  50.                         "    cin.tie(0);",
  51.                         "",
  52.                         "    return 0;",
  53.                         "}",
  54.                         ""
  55.                 ]
  56.         }
  57. }
复制代码
在 cpp 程序中,若是我的缺省源,输入 Problem 或 Contest 就会激活缺省源,具体效果如图:
14.png

如果觉得手动打缺省源太累了的话,可以使用以下代码:
[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
您需要登录后才可以回帖 登录 | 立即注册