一个 OIer 的编译命令 & 缺省源文件
编译命令
-Wno-unused-result 是为了防止没有使用 freopen 的返回值从而产生警告。
(NOI)Linux
- 在
~/.bashrc末尾添加:
cpl () {
g++ "./$1.cpp" -o "./$1" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result -Wl,-z,stack-size=1000000000 -fsanitize=undefined,bounds && echo "Compiled ./$1.cpp"
}
run () {
cpl "$1" && echo -e "Running ./$1\n" && time "./$1"
}
zp() {
zip -r "./$1.zip" "./$1" && echo "Compressed folder ./$1"
}
- 可在控制台内运行如下命令以重新加载
~/.bashrc中的命令:
source ~/.bashrc
Windows
- 在(VSCode 中的)Powershell 内运行(用户名不是
Administrator的自行改为实际用户名):
cd C:\Users\Administrator\Documents
mkdir .\WindowsPowerShell
cd .\WindowsPowerShell
type nul > Microsoft.VSCode_profile.ps1
type nul > Microsoft.PowerShell_profile.ps1
code Microsoft.VSCode_profile.ps1
code Microsoft.PowerShell_profile.ps1
- 在打开的文件中添加:
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=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result "-Wl,--stack=1000000000" # 神秘 Windows 没法加 "-fsanitize=undefined,bounds"
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" -ForegroundColor Cyan
Write-Host "---------------begin---------------" -ForegroundColor Cyan
$sw = [System.Diagnostics.Stopwatch]::StartNew()
& ".\$name.exe"
$sw.Stop()
Write-Host "`n----------------end----------------" -ForegroundColor Yellow
Write-Host "Time: $($sw.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow
}
}
- 可在(VSCode 中的)Powershell 内运行如下命令以重新加载 PowerShell 配置文件:
. $PROFILE
- 在部分特殊情况下,可以使用丐版命令来编译运行(将
$name的值替换为程序实际路径即可):
$name = ".\"; g++ "$name.cpp" -o "$name.exe" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result "-Wl,--stack=1000000000"; Write-Host "Compiled $name.cpp" -ForegroundColor Green; Write-Host "Running $name.exe" -ForegroundColor Cyan; Write-Host "---------------begin---------------" -ForegroundColor Cyan; $sw = [System.Diagnostics.Stopwatch]::StartNew(); & "$name.exe"; $sw.stop(); Write-Host "`n----------------end----------------" -ForegroundColor Yellow; Write-Host "Time: $($sw.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow
缺省源文件
VSCode cpp.json
"C++ Template": {
"prefix": "#cpp",
"body": [
"#include <bits/stdc++.h>",
"using namespace std;",
"#define int long long",
"#define ull unsigned long long",
"#define eb emplace_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;",
"",
"#if defined(__linux__) || defined(__linux)",
" #define gc getchar_unlocked",
"#elif defined(_WIN32) || defined(_WIN64)",
" #define gc _getchar_nolock",
"#else",
" #define gc getchar",
"#endif",
"",
"namespace IO { bool read(int &x) { x=0; char c = gc(); bool f=0; while (!isdigit(c)) { f|=(c=='-');",
"if (c==EOF) { return 0; } c=gc(); } while(isdigit(c)){ x = (x<<3)+(x<<1)+(c^48); c = gc(); } if (f)",
"{ x=-x; } return 1; } bool read(string &s) { s=\"\"; char c = gc(); while (!isprint(c) || isspace(c))",
"{ if (c==EOF) { return 0; } c=gc(); } while(isprint(c) && !isspace(c)){ s+=c; c=gc(); } return 1; }",
"bool read(char &c) { c = gc(); while(!isprint(c) || isspace(c)) { if(c==EOF){ return 0; } c = gc();",
"} 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++
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define eb emplace_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;
#if defined(__linux__) || defined(__linux)
#define gc getchar_unlocked
#elif defined(_WIN32) || defined(_WIN64)
#define gc _getchar_nolock
#else
#define gc getchar
#endif
namespace IO { bool read(int &x) { x=0; char c = gc(); bool f=0; while (!isdigit(c)) { f|=(c=='-');
if (c==EOF) { return 0; } c=gc(); } while(isdigit(c)){ x = (x<<3)+(x<<1)+(c^48); c = gc(); } if (f)
{ x=-x; } return 1; } bool read(string &s) { s=""; char c = gc(); while (!isprint(c) || isspace(c))
{ if (c==EOF) { return 0; } c=gc(); } while(isprint(c) && !isspace(c)){ s+=c; c=gc(); } return 1; }
bool read(char &c) { c = gc(); while(!isprint(c) || isspace(c)) { if(c==EOF){ return 0; } c = gc();
} 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;
}