C++ 快读快写模板

这是目前我知道的最快的快读写了,使用 fread() 重写了 getchar() 函数,在调试时需要注释掉第二行(即重写 getchar() 行),提交代码时取消掉注释即可,因为 fread() 仅能使用文件操作读入

如果数据范围和int范围不一样记得修改数据类型

支持负数版

#include<bits/stdc++.h>
#define in read()
using namespace std;
#define getchar() (S==T&&(T=(S=B)+fread(B,1,1<<15,stdin),S==T)?EOF:*S++)
char B[1<<15],*S=B,*T=B;
inline int read()
{
    char c=getchar();
    int x=0,f=1;
    while(c<48){if(c=='-')f=-1;c=getchar();}
    while(c>47)x=(x*10)+(c^48),c=getchar();
    return x*f;
}
inline void mwrite(int a)
{
    if(a>9)mwrite(a/10);
    putchar((a%10)|48);
}
inline void write(int a,char c)
{
	mwrite(a<0?(putchar('-'),a=-a):a);
	putchar(c);
}
signed main()
{
	
    return 0;
}

不支持负数版

#include<bits/stdc++.h>
#define in read()
using namespace std;
#define getchar() (S==T&&(T=(S=B)+fread(B,1,1<<15,stdin),S==T)?EOF:*S++)
char B[1<<15],*S=B,*T=B;
inline int read()
{
    char c=getchar();
    int x=0;
    while(c<48)c=getchar();
    while(c>47)x=(x*10)+(c^48),c=getchar();
    return x;
}
inline void mwrite(int a)
{
    if(a>9)mwrite(a/10);
    putchar((a%10)|48);
}
inline void write(int a,char c)
{
	mwrite(a);
	putchar(c);
}
signed main()
{
	
    return 0;
}
原文地址:https://www.cnblogs.com/cmy-blog/p/cppfastrw.html