基于 fread 与 fwrite 的快读快写模板
namespace CustomIO {
char inbuf[1<<12],outbuf[1<<18],num[18],*p1=inbuf,*p2=inbuf;
int p=0,p3=-1;
inline char getc() { return p1==p2&&(p2=(p1=inbuf)+fread(inbuf,1,1<<12,stdin),p1==p2)?EOF:*p1++; }
inline void flush() { fwrite(outbuf,1,p3+1,stdout),p3=-1; }
template<typename _Tp> inline void read(_Tp &x) {
int f=1; char ch=getc(); x=0;
while(!isdigit(ch)) ch=='-'&&(f*=-1),ch=getc();
while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getc();
x*=f;
}
template<typename _Tp> void write(_Tp x,const signed char tail=-1) {
p3>1<<12&&(flush(),0);
x<0&&(outbuf[++p3]='-',x*=-1);
do { num[++p]=x%10+48; } while(x/=10);
do { outbuf[++p3]=num[p]; } while(--p);
~tail&&(outbuf[++p3]=tail);
}
inline void read(char &ch) {
ch=getc();
while(!isgraph(ch)) ch=getc();
}
inline void read(std::string &s) {
char ch=getc(); s="";
while(!isgraph(ch)) ch=getc();
while(isgraph(ch)) s+=ch,ch=getc();
}
inline void write(const char *x) { while(*x) outbuf[++p3]=*x++; }
inline void write(const std::string &s,const signed char tail=-1) {
for(auto ch:s) outbuf[++p3]=ch;
~tail&&(outbuf[++p3]=tail);
}
}
using CustomIO::read;
using CustomIO::write;
using CustomIO::flush;把 getchar 实现成 getc,putchar(char ch) 实现成 outbuf[++p3]=ch 就可以在 基于可变参数模板的快速读写 中使用 fread 和 fwrite 的实现版本了