VScode 快速配置

· · 个人记录

本教程只针对OI。

  1. 安装 VSCODE。

  2. 下载 MinGW:Winlibs、MinGW-w64 - for 32 and 64 bit Windows Files ,并将 .\bin 添加到系统环境变量。 :::info[对于 Linux] 对于 NOI Linux 2.0 一般默认内置了 G++ 9.3.0。

    可以输入 g++ --version 查询,若安装则会返回:

       g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
       Copyright (C) 2019 Free Software Foundation, Inc.
       This is free software; see the source for copying conditions.  There is NO
       warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    否则,请执行:

       sudo apt update # 更新,可注释
       sudo apt install build-essential # 下载 gcc、g++
       sudo apt install gdb # 下载 gdb

    :::

  3. 安装插件

     C/C++
     Code Runner
     vscode-pdf
     Material Icon Theme
     ...
  4. 安装好后,新建一个文件:Hello.cpp,点击右上角按钮运行,或 Ctrl+Alt+N。

     #include <bits/stdc++.h>
     using namespace std;
     int main() {
         cout << "Hello world!" << endl;
         return 0;
     }
  5. 更改一些设置 找到 Code Runner 的设置,进入。

    勾选:

    Code-runner: Run In Terminal

    • [x] Whether to run code in Integrated Terminal.

    同时打开 Code-runner: Executor Map 找到: "cpp":... 替换为

    For Windows:

    "cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt.exe\" && & \".\\$fileNameWithoutExt.exe\"",

    For Linux:

    
    "cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt\" -O2 -std=c++14 -static && \"./$fileNameWithoutExt\"",```。