跳到正文

个人记录

超级好用的快读快写模板!

like_tis约 2 分钟
原文
文章信息与版本

文章信息

发布
2023年12月3日
收录
2025年12月12日
更新
2026年11月6日
篇幅
约 2 分钟

版本

  1. v1当前
C++
namespace FAST_IO{
	const int LEN=1<<17;
	char BUF[LEN],PUF[LEN];
	int Pin=LEN,Pout;
	inline void flushin(){memcpy(BUF,BUF+Pin,LEN-Pin),fread(BUF+LEN-Pin,1,Pin,stdin),Pin=0;return;}
	inline void flushout(){fwrite(PUF,1,Pout,stdout),Pout=0;return;}
	inline char Getc(){return (Pin==LEN?(fread(BUF,1,LEN,stdin),Pin=0):0),BUF[Pin++];}
	inline char Get(){return BUF[Pin++];}
	inline void Putc(char x){if(Pout==LEN)flushout(),Pout=0;PUF[Pout++]=x;}
	inline void Put(char x){PUF[Pout++]=x;}
	template<typename tp=int>inline tp read(){(Pin+32>=LEN)?flushin():void();tp res=0;char f=1,ch=' ';for(;ch<'0'||ch>'9';ch=Get())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=Get())res=(res<<3)+(res<<1)+ch-48;return res*f;}
	template<typename tp>inline void wt(tp a){if(a>9)wt(a/10);Put(a%10+'0');return;}
	template<typename tp>inline void write(tp a,char b='\n')
	{
		static int stk[20],top;
		(Pout+32>=LEN)?flushout():void();
		if(a<0)Put('-'),a=-a;
		else if(!a)Put('0');
		for(!top;a;a/=10)stk[++top]=a%10;
		for(;top;--top)Put(stk[top]^48);
		Put(b);
		return;
	}
}
using namespace FAST_IO;

使用方法:

C++
n=read();
write(n,' ');

注意事项:

  • 在 main 函数结尾加上 flushout();否则不输出

  • 输入完要输 Ctrl+Z (文件结束符),文件输入也可。

原文