关于快速读写
  • 板块学术版
  • 楼主fzj2007
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/1/25 20:39
  • 上次更新2023/10/28 10:57:46
查看原帖
关于快速读写
172370
fzj2007楼主2022/1/25 20:39

RT,刚刚重构了一份,然而出现了一点问题......

#include<iostream>
#include<iomanip>
#include<cstring>
#include<stack>
#include<vector>
#include<string>
#include<map>
#include<cstdlib>
#include<queue>
#include<math.h>
#include<time.h>
#include<set>
#include<cstdio>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct fastIO{
	bool digit(char ch){
		return ch>='0'&&ch<='9';
	}
	fastIO(){}
	fastIO &operator>>(char *s){
		int len=0;
		char ch=getchar();
		while(ch==' '||ch=='\n') ch=getchar();
		while(ch!=' '&&ch!='\n'&&ch!='\r') s[len++]=ch,ch=getchar();
		return *this;
	}
	template<typename T>
	fastIO &operator>>(T &res){
		res=0;
		bool flag=0;
		char ch=getchar();
		while(!digit(ch)) flag=(ch=='-'||flag),ch=getchar();
		while(digit(ch)) res=res*10+ch-'0',ch=getchar();
		if(ch!='.'){
			res=flag?-res:res;
			return *this;
		}
		double base=0.1;
		while(!digit(ch)) ch=getchar();
		while(digit(ch)) res+=base*(ch-'0'),base/=10.0,ch=getchar();
		res=flag?-res:res;
		return *this;
	}
	fastIO &operator<<(char ch){
		putchar(ch);
		return *this;
	}
	fastIO &operator<<(char *s){
		int len=strlen(s);
		for(int i=0;i<len;i++) putchar(s[i]);
		return *this;
	}
	fastIO &operator<<(string s){
		int len=s.length();
		for(int i=0;i<len;i++) putchar(s[i]);
		return *this;
	}
	char OUT_Put[105];
	template<typename T>
	fastIO &operator<<(T x){
		if(x<0) putchar('-'),x=-x;
		int i=0;
		while(x) OUT_Put[++i]=x%10+'0',x/=10;
		while(i) putchar(OUT_Put[i--]);
		return *this;
	}
}io;
int n,m; 
int main(){
	io>>n>>m;
	io<<n<<" "<<m<<'\n';
	return 0;
}

然而上面这份代码会报错。

问题在于

template<typename T>//这里
fastIO &operator<<(T x){
	if(x<0) putchar('-'),x=-x;
	int i=0;
	while(x) OUT_Put[++i]=x%10+'0',x/=10;
	while(i) putchar(OUT_Put[i--]);
	return *this;
}

然后下面调用的时候使用的 " " 没有直接被转换为上面的*charstring类型,需要手动强转。

现想求教是否有其他解决方法/kk

2022/1/25 20:39
加载中...