跳到正文

个人记录

一个 OIer 的编译命令 & 缺省源文件

W_C_B_H约 11 分钟
原文

这是 2026年2月7日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年2月7日
收录
2026年2月7日
更新
2026年10月6日
篇幅
约 11 分钟

版本

  1. v8当前
  2. v7
  3. v6
  4. v5
更早的 4 个版本
  1. v4
  2. v3
  3. v2
  4. v1

编译命令

(NOI)Linux

  1. 在 ~/.bashrc 末尾添加:
Bash
cpl () {
    g++ "./$1.cpp" -o "./$1" -O2 -std=c++14 -static -Wall -Wextra && echo "Compiled ./$1.cpp"
}
run () {
    cpl "$1" && echo -e "Running ./$1\n" && time "./$1"
}
zp() {
    zip -r "./$1.zip" "./$1" && echo "Compressed folder ./$1"
}
  1. 可在控制台内运行如下命令以重新加载 ~/.bashrc 中的命令:
Bash
source ~/.bashrc

Windows

  1. 在(VSCode 中的)Powershell 内运行:
powershell
New-Item -Path $PROFILE -Type File -Force
code $PROFILE
  1. 在打开的 Microsoft.VSCode_profile.ps1 中添加:
powershell
function cpl {
    param([string]$name)
    $cppFile = ".\$name.cpp"
    $exeFile = ".\$name.exe"
    if (-not (Test-Path $cppFile)) { 
        Write-Error "Error: $cppFile not found"; return 
    }
    g++ "$cppFile" -o "$exeFile" -O2 -std=c++14 -static -Wall -Wextra
    if ($LASTEXITCODE -eq 0) { 
        Write-Host "Compiled $cppFile" -ForegroundColor Green 
    }
}
function run {
    param([string]$name)
    cpl $name
    if ($LASTEXITCODE -eq 0 -and (Test-Path ".\$name.exe")) {
        Write-Host "Running .\$name.exe`n" -ForegroundColor Cyan
        $sw = [System.Diagnostics.Stopwatch]::StartNew()
        & ".\$name.exe"
        $sw.Stop()
        Write-Host "`nTime: $($sw.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow
    }
}
  1. 可在(VSCode 中的)Powershell 内运行如下命令以重新加载 PowerShell 配置文件:
powershell
. $PROFILE

缺省源文件

VSCode cpp.json

JSON
    "C++ Template": {
        "prefix": "#cpp",
        "body": [
            "#include<bits/stdc++.h>",
            "using namespace std;",
            "#define int long long",
            "#define ull unsigned long long",
            "#define pb push_back",
            "#define pii pair<int,int>",
            "#define p3i pair<int,pii>",
            "#define fi first",
            "#define se second",
            "#define all(a) (a).begin(),(a).end()",
            "const int inf=0x3f3f3f3f, llinf=0x3f3f3f3f3f3f3f3f;",
            "namespace IO",
            "{",
            "    bool read(int &x){ x=0; char c=getchar(); bool f=0; while(!isdigit(c)){ f|=(c=='-'); if(c==EOF) return 0; c=getchar(); }",
            "        while(isdigit(c)){ x=(x<<3)+(x<<1)+(c^48); c=getchar(); } if(f) x=-x; return 1; }",
            "    bool read(string &s){ s=\"\"; char c=getchar(); while(!isprint(c) || isspace(c)){ if(c==EOF) return 0; c=getchar(); }",
            "        while(isprint(c) && !isspace(c)){ s+=c; c=getchar(); } return 1; }",
            "    bool read(char &c){ c=getchar(); while(!isprint(c) || isspace(c)){ if(c==EOF) return 0; c=getchar(); } return 1; }",
            "    template<typename T,typename... U> bool read(T &x,U&... y){ if(!read(x)) return 0; return read(y...); }",
            "    void write(int x){ if(x<0){ putchar('-'); x=-x; } string s=\"\"; do{ s+=x%10^48; x/=10; }while(x); reverse(all(s)); for(char c:s) putchar(c); }",
            "    void write(char c){ putchar(c); } void write(const char *s){ while(*s) putchar(*s++); } void write(string x){ for(char c:x) putchar(c); }",
            "    template<typename T,typename... U> void write(T x,U... y){ write(x); write(y...); }",
            "    template<typename T,typename... U> void writeln(T x,U... y){ write(x,y...); puts(\"\"); }",
            "}",
            "namespace W_C_B_H",
            "{",
            "    using namespace IO;",
            "    void main()",
            "    {",
            "    }",
            "}",
            "signed main()",
            "{",
            "    // freopen(\".in\",\"r\",stdin);",
            "    // freopen(\".out\",\"w\",stdout);",
            "    W_C_B_H::main();",
            "    return 0;",
            "}",
        ],
        "description": "C++ 缺省源"
    }

Dev-C++

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int,int>
#define p3i pair<int,pii>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
const int inf=0x3f3f3f3f, llinf=0x3f3f3f3f3f3f3f3f;
namespace IO
{
	bool read(int &x){ x=0; char c=getchar(); bool f=0; while(!isdigit(c)){ f|=(c=='-'); if(c==EOF) return 0; c=getchar(); }
		while(isdigit(c)){ x=(x<<3)+(x<<1)+(c^48); c=getchar(); } if(f) x=-x; return 1; }
	bool read(string &s){ s=""; char c=getchar(); while(!isprint(c) || isspace(c)){ if(c==EOF) return 0; c=getchar(); }
		while(isprint(c) && !isspace(c)){ s+=c; c=getchar(); } return 1; }
	bool read(char &c){ c=getchar(); while(!isprint(c) || isspace(c)){ if(c==EOF) return 0; c=getchar(); } return 1; }
	template<typename T,typename... U>	bool read(T &x,U&... y){ if(!read(x)) return 0; return read(y...); }
	void write(int x){ if(x<0){ putchar('-'); x=-x; } string s=""; do{ s+=x%10^48; x/=10; }while(x); reverse(all(s)); for(char c:s) putchar(c); }
	void write(char c){ putchar(c); }	void write(const char *s){ while(*s) putchar(*s++); }	void write(string x){ for(char c:x) putchar(c); }
	template<typename T,typename... U>	void write(T x,U... y){ write(x); write(y...); }
	template<typename T,typename... U>	void writeln(T x,U... y){ write(x,y...); puts(""); }
}
namespace W_C_B_H
{
	using namespace IO;
	void main()
	{
	}
}
signed main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	W_C_B_H::main();
	return 0;
}