MacOS 自用 VSCode 缺省源 & Clang 配置文件
MacOS 自用 VSCode 缺省源 & Clang 配置文件
目前是 C++20 ,编译器为 Clang v16 ,本文更新于 2026 年 11 月 15 日。
之前有几个文件混杂了制表符,乱七八糟的,现在全部改成 4 个空格了。
一、缺省源
这个缺省源就是输入开头几个字符,然后点回车就能直接出现的模板。
打开方式为 command + shift + p
,输入 Configure User Snippets ,点击 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"
// }
// 本模板更新于 2026 年 11 月 15 日
// 于2024年8月10日更新
// 头文件Mac
// 增加template
"#include":
{
"prefix":"#include",
"body":
[
"#include <bits/stdc++.h>",
"using namespace std;",
"#define int long long",
"#define INF 0x3f3f3f3f3f3f3f3f",
"template<typename T> void up(T &x, T y) { x < y ? x = y : 0; }",
"template<typename T> void down(T &x, T y) { x > y ? x = y : 0; }",
"#define rep(i, a, b) for(int i = (a), i##END = (b); i <= i##END; i++)",
"#define Rep(i, a, b) for(int i = (a), i##END = (b); i >= i##END; i--)",
"#define N ((int)())",
"",
"",
"signed main()",
"{",
" ios::sync_with_stdio(0);",
" cin.tie(0); cout.tie(0);",
" // freopen(\"check.in\",\"r\",stdin);",
" // freopen(\"check.out\",\"w\",stdout);",
" ",
" return 0;",
"}"
]
},
// 于2024年7月22日更新
// 更新了代码风格
"FastIO":
{
"prefix":"FastIO",
"body":
[
"namespace FastIO",
"{",
" #define gc() readchar()",
" #define pc(a) putchar(a)",
" #define SIZ (int)(1e6 + 15)",
" char buf1[SIZ], *p1, *p2;",
" char readchar()",
" {",
" if(p1 == p2) { p1 = buf1, p2 = buf1 + fread(buf1, 1, SIZ, stdin); }",
" return p1 == p2? EOF : *p1++;",
" }",
" template<typename T>void read(T &k)",
" {",
" char ch = gc(); T x = 0, f = 1;",
" while(!isdigit(ch)) { if(ch == '-') { f = -1; } ch = gc(); }",
" while(isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = gc(); }",
" k = x * f;",
" }",
" template<typename A, typename ...B>",
" void read(A &x, B &...y) { return read(x), read(y...); }",
" template<typename T>void write(T k)",
" {",
" if(k < 0){ k = -k; pc('-'); }",
" static T stk[66]; T top = 0;",
" do{ stk[top++] = k % 10, k /= 10; } while(k);",
" while(top) { pc(stk[--top] + '0'); }",
" }",
"}using namespace FastIO;"
]
},
// 于2022年09月11日更新
// CodeForces 快速模板
// #include <bits/stdc++.h>
"cf_CodeForces_template":
{
"prefix":"cf_CodeForces_template",
"body":
[
"#include <bits/stdc++.h>",
"using namespace std;",
"#define int long long",
"#define INF 0x3f3f3f3f3f3f3f3f",
"void up(int &x,int y) { x < y ? x = y : 0; }",
"void down(int &x,int y) { x > y ? x = y : 0; }",
"#define N ((int)())",
"",
"void solve()",
"{",
" // clear();",
"}",
"signed main()",
"{",
" ios::sync_with_stdio(0);",
" cin.tie(0);cout.tie(0);",
" // freopen(\"check.in\",\"r\",stdin);",
" // freopen(\"check.out\",\"w\",stdout);",
" int _Q=1;// cin >> _Q;",
" while(_Q--)solve();",
" return 0;",
"}"
]
},
// 于2022年9月11日更新
// poj 刷题模板
// 改错了233333333
"poj_template":
{
"prefix":"poj_template",
"body":
[
"#include <iostream>",
"#include <string>",
"#include <vector>",
"#include <algorithm>",
"#include <cstdio>",
"#include <cstdlib>",
"#include <cstring>",
"#include <cmath>",
"#include <iomanip>",
"using namespace std;",
"#define int long long",
"#define INF 0x3f3f3f3f3f3f3f3f",
"void up(int &x,int y) { x < y ? x = y : 0; }",
"void down(int &x,int y) { x > y ? x = y : 0; }",
"#define N ((int)())",
"",
"",
"signed main()",
"{",
" ios::sync_with_stdio(0);",
" cin.tie(0);cout.tie(0);",
" // freopen(\"check.in\",\"r\",stdin);",
" // freopen(\"check.out\",\"w\",stdout);",
"",
"",
" return 0;",
"}"
]
},
// 于2022年9月27日更新
// 采用 fread() 进行读入
// 支持所有类型读入
"__fastio":
{
"prefix":"__fastio",
"body":
[
"namespace __fastio",
"{",
" const int bufl=1<<20;",
" const double base1[16]={1,1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,1e-12,1e-13,1e-14,1e-15};",
" const double base2[16]={1,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13,1e14,1e15};",
" struct IN{",
" FILE *IT;char ibuf[bufl],*is=ibuf,*it=ibuf;",
" IN(){IT=stdin;}IN(char *a){IT=fopen(a,\"r\");}",
" inline char getChar(){if(is==it){it=(is=ibuf)+fread(ibuf,1,bufl,IT);if(is==it)return EOF;}return *is++;}",
" template<typename Temp>inline void getInt(Temp &a)",
" {a=0;int b=0,c=getChar();while(c<48||c>57)b^=(c==45),c=getChar();while(c>=48&&c<=57)a=(a<<1)+(a<<3)+c-48,c=getChar();if(b)a=-a;}",
" template<typename Temp>inline void getDouble(Temp &a)",
" {a=0;int b=0,c=getChar(),d=0;__int128 e=0,f=0;while(c<48||c>57)b^=(c==45),c=getChar();while(c>=48&&c<=57)e=(e<<1)+(e<<3)+c-48,c=getChar();",
" if(c==46){c=getChar();while(c>=48&&c<=57)d++,f=(f<<1)+(f<<3)+c-48,c=getChar();}a=e+base1[d]*f;if(b)a=-a;}",
" IN& operator>>(char &a){a=getChar();return *this;}",
" IN& operator>>(char *a){do{*a=getChar();}while(*a<=32);while(*a>32)*++a=getChar();*a=0;return *this;}",
" IN& operator>>(string &a){char b=getChar();while(b<=32)b=getChar();while(b>32)a+=b,b=getChar();return *this;}",
" IN& operator>>(int &a){getInt(a);return *this;}",
" # ifndef int",
" IN& operator>>(long long &a){getInt(a);return *this;}",
" # endif",
" IN& operator>>(__int128 &a){getInt(a);return *this;}",
" IN& operator>>(float &a){getDouble(a);return *this;}",
" IN& operator>>(double &a){getDouble(a);return *this;}",
" # ifndef double",
" IN& operator>>(long double &a){getDouble(a);return *this;}",
" # endif",
" };",
" struct OUT{",
" FILE *IT;char obuf[bufl],*os=obuf,*ot=obuf+bufl;int Eps;long double Acc;",
" OUT(){IT=stdout,Eps=6,Acc=1e-6;}OUT(char *a){IT=fopen(a,\"w\"),Eps=6,Acc=1e-6;}",
" inline void ChangEps(int x=6){Eps=x;}",
" inline void flush(){fwrite(obuf,1,os-obuf,IT);os=obuf;}",
" inline void putChar(int a){*os++=a;if(os==ot)flush();}",
" template<typename Temp>inline void putInt(Temp a)",
" {if(a<0){putChar(45);a=-a;}if(a<10){putChar(a+48);return;}putInt(a/10);putChar(a%10+48);}",
" template<typename Temp>inline void putDouble(Temp a)",
" {if(a<0){putChar(45);a=-a;}__int128 b=a;putInt(b);a-=b;a*=base2[Eps];b=a+Acc;putChar(46);putInt(b);}",
" OUT& operator<<(char a){putChar(a);return *this;}",
" OUT& operator<<(char *a){while(*a>32)putChar(*a++);return *this;}",
" OUT& operator<<(string a){for(auto c:a)putChar(c);return *this;}",
" OUT& operator<<(int a){putInt(a);return *this;}",
" # ifndef int",
" OUT& operator<<(long long a){putInt(a);return *this;}",
" # endif",
" OUT& operator<<(__int128 a){putInt(a);return *this;}",
" OUT& operator<<(float a){putDouble(a);return *this;}",
" OUT& operator<<(double a){putDouble(a);return *this;}",
" # ifndef double",
" OUT& operator<<(long double a){putDouble(a);return *this;}",
" # endif",
" ~OUT(){flush();}",
" };",
"}using __fastio::IN;using __fastio::OUT; IN fin; OUT fout;"
]
},
// 于2022年11月21日更新
// 链式前向星板子
"__graph":
{
"prefix":"__graph",
"body":
[
"int pos=1,head[N];",
"struct Edge { int u,v,next; } e[];",
"void addEdge(int u,int v)",
"{ e[++pos] = {u,v,head[u]}; head[u] = pos; }"
]
},
}
二、配置文件
MacOS 没有万能头文件,需要自己去 bits/ 目录下新建一个
stdc++.h ,具体方法在本站搜“万能头文件”。
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - 生成和调试活动文件",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"cwd": "${fileDirname}",
"preLaunchTask": "C/C++: clang++ 生成活动文件"
}
]
}
settings.json
{
"files.associations": {
"iostream": "cpp",
"ios": "cpp",
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"variant": "cpp",
"vector": "cpp",
"__functional_base": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"utility": "cpp",
"p4999": "cpp",
"stack": "cpp",
"list": "cpp",
"random": "cpp",
"numeric": "cpp",
"__availability": "cpp",
"thread": "cpp",
"filesystem": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"condition_variable": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"future": "cpp",
"regex": "cpp",
"scoped_allocator": "cpp",
"typeindex": "cpp",
"unordered_set": "cpp",
"valarray": "cpp"
},
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
// 编译警告指令参考 https://blog.csdn.net/weixin_42102584/article/details/88616467
"args": [
"-g", // 便于gdb调试
"-O2", // O2 优化
"-Wall", // 一堆警告,参考https://blog.csdn.net/u014044624/article/details/115221092
"-Wextra",
"-Wformat", // scanf & printf 传参检测
"-Wfloat-equal", // 浮点型直接用 == 比较会报警告
"-Wempty-body", // if,for,while等不小心加分号报警告
"-Wshadow", // 变量重名警告
"-Wuninitialized", // 警告未初始化的变量
"-Wreturn-type", // 非 void 函数无返回值警告
"-Wparentheses", // 警告可能缺失的大括号,例如if,if,else
"-Wsizeof-pointer-memaccess", // 警告 memset 中,第三个参数是对指针变量进行的 sizeof
"-Wconversion", // 警告可能造成数据范围损失的(自动)类型转换,如 long long 转 int
"-fsanitize=address", // 用于检测越界访问、释放后使用等内存错误
"${file}",
"-std=c++20",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: /usr/bin/clang++"
}
]
}
本博客所有文章除特别声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明来源 Q779’s Blog!




