---
# System prepended metadata

title: filebufio
tags: [codebook]

---

---
tags: codebook
---
{%hackmd theme-dark %}
# filebufio
```cpp=
#include<cstdio>
#include<string>
#include<cctype>
using namespace std;
constexpr size_t MAXN=1000000;
struct fileio{
	FILE *file;
	size_t len,cur;
	char buffer[MAXN];
	operator bool(){return cur<len;}
	friend inline fileio& getline(fileio& buf,string& str,char delim=EOF){
		str.clear();if(!buf){return buf;}
		while(buf.buffer[buf.cur]!='\n'&&buf&&buf.buffer[buf.cur]!=delim)
		{str.push_back(buf.buffer[buf.cur]);buf.cur++;}buf.cur++;return buf;}
	inline fileio& operator>>(int& re){
		re=0;bool b=false;
		while(!isdigit(buffer[cur])){if(cur>=len){return *this;}b=(buffer[cur]=='-'?true:b);cur++;}
		while(isdigit(buffer[cur])){re=re*10+buffer[cur]-'0',cur++;}
		re=b?-re:re; return *this;}
	inline fileio& operator>>(long long& re){
		re=0;bool b=false;
		while(!isdigit(buffer[cur])){if(cur>=len){return *this;}b=(buffer[cur]=='-'?true:b);cur++;}
		while(isdigit(buffer[cur])){re=re*10+buffer[cur]-'0',cur++;}
		re=b?-re:re; return *this;}
	inline fileio& operator>>(unsigned& re){
		re=0;while(!isdigit(buffer[cur])){if(cur>=len){return *this;}cur++;}
		if(cur>=len){return *this;}
		while(isdigit(buffer[cur])){re=re*10+buffer[cur]-'0',cur++;}return *this;}
	inline fileio& operator>>(unsigned long long& re){
		re=0;while(!isdigit(buffer[cur])){if(cur>=len){return *this;}cur++;}
		if(cur>=len){return *this;}
		while(isdigit(buffer[cur])){re=re*10+buffer[cur]-'0',cur++;}return *this;}
	inline fileio& operator>>(string& re){
		re.clear();while(isspace(buffer[cur])) cur++;
		if(cur>=len){return *this;}
		while(isprint(buffer[cur])&&!isspace(buffer[cur]))
		{re.push_back(buffer[cur]),cur++;}return *this;}
	inline fileio& operator>>(char& x){
		while(isspace(buffer[cur])) cur++;
		x=buffer[cur];return *this;}
	fileio(const string& str):cur(0){
		file=fopen((str).data(),"rb");
		len=fread(buffer,sizeof(char),MAXN,file);
		buffer[len]='\n',len++;
		buffer[len]=0,len++;
		fclose(file);
	}
};
```