一个基于 fread 和 fwrite 的 C++ 快速输入输出模板(Fast I/O)。
# 源码
#include <bits/stdc++.h>
using namespace std;
namespace fastio {
static constexpr int SZ = 1 << 20;
char inbuf[SZ], outbuf[SZ], *p1 = inbuf, *p2 = inbuf, *p3 = outbuf;
inline char gc() {
return p1 == p2 && (p2 = (p1 = inbuf) + fread(inbuf, 1, SZ, stdin), p1 == p2) ? EOF : *p1++;
}
inline void pc(char c) {
if (p3 == outbuf + SZ) fwrite(outbuf, 1, SZ, stdout), p3 = outbuf;
*p3++ = c;
}
struct Flush {
~Flush() { fwrite(outbuf, 1, p3 - outbuf, stdout); }
} call_flush;
template <typename T>
inline void read(T &x) {
x = 0; char c = gc(); bool f = false;
while (!isdigit(c)) f |= (c == '-'), c = gc();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = gc();
if (f) x = -x;
}
template <typename T, typename... Args>
inline void read(T &x, Args &... args) {
read(x), read(args...);
}
inline void read(char &c) {
while ((c = gc()) <= 32);
}
inline void read(string &s) {
s = ""; char c = gc();
while (c <= 32) c = gc();
while (c > 32) s += c, c = gc();
}
template <typename T>
inline void print(T x) {
if (x < 0) pc('-'), x = -x;
if (x > 9) print(x / 10);
pc(x % 10 + '0');
}
inline void print(char c) { pc(c); }
inline void print(const string &s) {
for (char c : s) pc(c);
}
inline void print(const char *s) {
while (*s) pc(*s++);
}
template <typename T, typename... Args>
inline void print(T x, Args... args) {
print(x), print(args...);
}
}
using namespace fastio;
int main() {
// 示例用法
int a, b;
read(a, b);
print(a + b, '\n');
return 0;
}
