array.h
Fyq_20
·
·
科技·工程
#include"ioput.h"
#include<array>
namespace std
{
template<typename T,size_t lenth>
class array_in_io:public array<T,lenth>
{
public:
int l,r;
array_in_io()
{
l=r=-1;
}
array_in_io &operator()(int len)
{
l=0,r=len-1;
return *this;
}
array_in_io &operator()(int _l,int _r)
{
l=_l-1;
r=_r-1;
return *this;
}
};
template<typename T,size_t lenth>
istream& operator>>(istream& x,array_in_io<T,lenth> &arr)
{
if(arr.l==-1&&arr.r==-1)
{
cerr<<"Array size not found\n";
return x;
}
int l=arr.l,r=arr.r;
for(int i=l;i<=r;i++)
{
if(i>=lenth){
cerr<<"The size of array is too small\n";
break;
}
x>>arr[i];
}
arr.l=arr.r=-1;
return x;
}
template<typename T,size_t lenth>
ostream& operator<<(ostream& x,array_in_io<T,lenth> &arr)
{
if(arr.l==-1&&arr.r==-1)
{
cerr<<"Array size not found\n";
return x;
}
int l=arr.l,r=arr.r;
bool tmp=output_form;
bool flag=output_form&&(output_format=="/array"||output_format=="/auto");
if(!flag&&output_format[0]=='/')output_form=0;
if(r>=lenth)r=lenth-1;
if(flag)x<<"Array=[";
for(int i=l;i<=r;i++)
{
x<<arr[i];
if(flag)
{
if(i!=r)x<<",";
continue;
}
if(output_form)x<<output_format;
}
if(flag)x<<"]\n";
return x;
}
}
#define array array_in_io